migrate to net/http, update go mod
tronnet/workflows: Static Analysis -- Golang / static-go (push) Successful in 31s
tronnet/workflows: Static Analysis -- Golang / static-go (push) Successful in 31s
This commit is contained in:
1 parent
b9538a6337
commit
590486f153
4 files changed
+68
-69
No files matched your search
@@ -3,6 +3,7 @@ package app
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
@@ -63,3 +64,16 @@ 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