package response import ( "encoding/json" "net/http" ) // JSON writes v as JSON with the given status code. func JSON(rw http.ResponseWriter, status int, v any) { rw.Header().Set("Content-Type", "application/json") rw.WriteHeader(status) if v != nil { _ = json.NewEncoder(rw).Encode(v) } } // JSONError writes an error response in standard format: {"error": "message", "code": "CODE"}. func JSONError(rw http.ResponseWriter, status int, msg string, code string) { rw.Header().Set("Content-Type", "application/json") rw.WriteHeader(status) _ = json.NewEncoder(rw).Encode(map[string]string{ "error": msg, "code": code, }) }