add http html and html fragment template execute code to common lib
tronnet/workflows: Static Analysis -- Golang / static-go (push) Failing after 22s
tronnet/workflows: Static Analysis -- Golang / static-go (push) Failing after 22s
This commit is contained in:
1 parent
8284ffbc43
commit
01c1f0389a
1 file changed
+33
@@ -0,0 +1,33 @@
|
|||||||
|
package proxmoxaas_common_lib
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"html/template"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func HTTPExecuteHTMLTemplate(w http.ResponseWriter, t *template.Template, name string, d any) {
|
||||||
|
w.Header().Set("Content-Type", "text/html")
|
||||||
|
body := bytes.Buffer{}
|
||||||
|
err := t.ExecuteTemplate(&body, name, d)
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
w.Write(body.Bytes())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func HTTPExecuteHTMLFragmentTemplate(w http.ResponseWriter, t *template.Template, name string, d any) {
|
||||||
|
w.Header().Set("Content-Type", "text/plain")
|
||||||
|
body := bytes.Buffer{}
|
||||||
|
err := t.ExecuteTemplate(&body, name, d)
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
w.Write(body.Bytes())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user