mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-06 16:40:32 +00:00
fix: api ok nil response
This commit is contained in:
1 parent
aa9577a2e0
commit
3523f5855a
1 file changed
+6
-4
@@ -15,13 +15,15 @@ func ReadJson(w http.ResponseWriter, r *http.Request, v any) bool {
|
||||
}
|
||||
|
||||
func WriteJsonOk(w http.ResponseWriter, v any) {
|
||||
WriteJson(w, http.StatusOK, v)
|
||||
if v == nil {
|
||||
WriteJson(w, http.StatusOK, model.NewResultWithData[any](nil))
|
||||
} else {
|
||||
WriteJson(w, http.StatusOK, v)
|
||||
}
|
||||
}
|
||||
|
||||
func WriteJson(w http.ResponseWriter, code int, v any) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(code)
|
||||
if v != nil {
|
||||
json.NewEncoder(w).Encode(v)
|
||||
}
|
||||
json.NewEncoder(w).Encode(v)
|
||||
}
|
||||
Reference in new issue
Block a user