add JSON helper to HTTP utils
tronnet/workflows: Static Analysis -- Golang / static-go (push) Failing after 21s

This commit is contained in:
alu committed 2026-10-23 21:55:27 +00:00
1 parent 01c1f0389a
commit 35ecaf84e0
1 file changed
+14
+14
View File
@@ -2,6 +2,7 @@ package proxmoxaas_common_lib
import ( import (
"bytes" "bytes"
"encoding/json"
"html/template" "html/template"
"net/http" "net/http"
) )
@@ -31,3 +32,16 @@ func HTTPExecuteHTMLFragmentTemplate(w http.ResponseWriter, t *template.Template
return return
} }
} }
func HTTPWriteJson(w http.ResponseWriter, code int, obj any) {
w.Header().Set("Content-Type", "application/json")
json, err := json.Marshal(obj)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
} else {
w.WriteHeader(code)
w.Write(json)
return
}
}