writeJSON encodes payload as the response body. Logs encoding errors rather than swallowing them — an Encode failure usually means the client closed the connection mid-response or the payload contains a non-marshalable value, both of which are useful to surface in logs when debugging truncated respo
(w http.ResponseWriter, payload any)
| 46 | // non-marshalable value, both of which are useful to surface in logs |
| 47 | // when debugging truncated responses. |
| 48 | func writeJSON(w http.ResponseWriter, payload any) { |
| 49 | if err := json.NewEncoder(w).Encode(payload); err != nil { |
| 50 | log.Printf("[api] json encode failed: %v", err) |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | // readJSON wraps the request body in a MaxBytesReader and decodes into |
| 55 | // dst. Use this for every JSON-decoding handler to bound memory and |
no outgoing calls
no test coverage detected