更新json序列化忽略字段

This commit is contained in:
langhuihui
2022-05-03 14:38:59 +08:00
parent a61bec993b
commit d9bf97fe51
6 changed files with 27 additions and 21 deletions

View File

@@ -12,7 +12,7 @@ import (
func ReturnJson[T any](fetch func() T, tickDur time.Duration, rw http.ResponseWriter, r *http.Request) {
if r.URL.Query().Get("json") != "" {
if err := json.NewEncoder(rw).Encode(fetch()); err != nil {
rw.WriteHeader(500)
http.Error(rw, err.Error(), http.StatusInternalServerError)
}
return
}