use json helper from common-lib HTTP helper
tronnet/workflows: Static Analysis -- Golang / static-go (push) Successful in 39s
tronnet/workflows: Static Analysis -- Golang / static-go (push) Successful in 39s
This commit is contained in:
1 parent
590486f153
commit
612fbddb33
3 files changed
+19
-32
No files matched your search
@@ -3,7 +3,6 @@ package app
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
@@ -64,16 +63,3 @@ func AnyPrefixes(s string, prefixes []string) string {
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
func WriteJson(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
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user