Documentation
¶
Index ¶
Constants ¶
View Source
const ( ErrInvalidContentTypeField = "Content-Type" ErrMaxBodySizeExceeded = "json body size exceeds the maximum allowed size, limit is %d bytes" ErrSyntaxError = "json body contains badly-formed JSON at position %d" ErrUnknownField = "json body contains an unknown field %s" )
Variables ¶
View Source
var ( ErrCodeNilRequest string ErrCodeInvalidContentType string ErrCodeInvalidBodyType string ErrCodeUnmarshalRequestBodyFailed string ErrCodeSyntaxError string ErrCodeUnmarshalTypeError string ErrCodeUnknownField string ErrCodeEmptyBody string ErrCodeMaxBodySizeExceeded string )
View Source
var ( ErrNilRequest = errors.New("request cannot be nil") ErrInvalidContentType = errors.New("invalid content type, expected application/json") ErrInvalidBodyType = errors.New("invalid body type, expected struct") ErrUnexpectedEOF = errors.New("json body contains badly-formed JSON") ErrEmptyBody = errors.New("json body is empty") ErrUnmarshalBodyFailed = errors.New("failed to unmarshal json body") )
Functions ¶
func BodyDecodeErrorHandler ¶ added in v0.12.5
BodyDecodeErrorHandler handles the error on JSON body decoding
Parameters:
- err: The error that occurred during decoding
Returns:
- error: An error if the encoder is nil or if encoding the response fails
func CheckContentType ¶ added in v0.12.2
CheckContentType checks if the content type is JSON
Parameters:
- r: The HTTP request
Returns:
- bool: True if the content type is JSON, false otherwise
Types ¶
Click to show internal directories.
Click to hide internal directories.