JSON encodes the provided message as JSON. When a marshalling error is encountered, Error is used in order to handle the error.
(w http.ResponseWriter, r *http.Request, i any)
| 146 | // JSON encodes the provided message as JSON. When a marshalling error |
| 147 | // is encountered, Error is used in order to handle the error. |
| 148 | func JSON(w http.ResponseWriter, r *http.Request, i any) { |
| 149 | b, err := json.Marshal(i) |
| 150 | if err != nil { |
| 151 | Error(w, r, err) |
| 152 | return |
| 153 | } |
| 154 | w.Header().Set("Content-Type", "application/json") |
| 155 | _, _ = w.Write(b) |
| 156 | } |
no test coverage detected