Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var BodyMaxSize int64 = 1048576 // 1MB
BodyMaxSize is the maximum size of a json body
Functions ¶
func DecodeJSONBody ¶
func DecodeJSONBody(w http.ResponseWriter, r *http.Request, dst interface{}) error
DecodeJSONBody is a modified version of https://www.alexedwards.net/blog/how-to-properly-parse-a-json-request-body Attempts to decode a json request body into dst, returning an error if it fails
func ErrorJSON ¶
func ErrorJSON(w http.ResponseWriter, error string, code int)
ErrorJSON is a replacement for http.Error for use by endpoints with Content-Type header "application/json". http.Error should not be used because it overwrites the Content-Type header to "text/plain"
func HandleJSONdecodeError ¶
func HandleJSONdecodeError(w http.ResponseWriter, err error)
HandleJSONdecodeError is a helperr function for responding to requests that cause decodeJSONBody to throw an error. Logs a detailed error message and responds to the client with a generic HTTP error message. The caller should ensure no further writes are done to w.
Types ¶
This section is empty.