Files
ad_fun/chessstars/internal/httpx/json.go
T
2026-07-15 13:29:08 +03:00

22 lines
457 B
Go

package httpx
import (
"encoding/json"
"net/http"
)
func WriteJSON(w http.ResponseWriter, status int, v any) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
_ = json.NewEncoder(w).Encode(v)
}
func Error(w http.ResponseWriter, status int, msg string) {
WriteJSON(w, status, map[string]any{"ok": false, "error": msg})
}
func ReadJSON(r *http.Request, v any) error {
dec := json.NewDecoder(r.Body)
return dec.Decode(v)
}