// Package httpx holds small HTTP helpers shared by middleware and handlers. package httpx import ( "encoding/json" "net/http" ) // WriteJSON writes value as JSON with the given status. A nil value, or 204 No // Content, writes no body. func WriteJSON(w http.ResponseWriter, status int, value any) { w.Header().Set("Content-Type", "application/json; charset=utf-8") w.WriteHeader(status) if value == nil || status == http.StatusNoContent { return } json.NewEncoder(w).Encode(value) //nolint:errcheck,gosec // the client may have gone }