Documentation
¶
Index ¶
Constants ¶
View Source
const ( 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 ( ErrCodeNilDestination string ErrCodeFailedToReadBody string ErrCodeUnmarshalRequestBodyFailed string ErrCodeSyntaxError string ErrCodeUnmarshalTypeError string ErrCodeUnknownField string ErrCodeEmptyBody string ErrCodeMaxBodySizeExceeded string )
View Source
var ( ErrUnexpectedEOF = errors.New("json body contains badly-formed JSON") ErrEmptyBody = errors.New("json body is empty") ErrUnmarshalBodyFailed = errors.New("failed to unmarshal json body") )
View Source
var ( ErrNilDestination = errors.New("json destination is nil") ErrInvalidInstance = errors.New("invalid instance provided to create a reader") )
Functions ¶
func BodyDecodeErrorHandler ¶
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
Types ¶
type Decoder ¶ added in v0.11.2
type Decoder struct {
// contains filtered or unexported fields
}
Decoder struct
func NewDecoder ¶ added in v0.11.2
func NewDecoder( mode *goflagsmode.Flag, ) *Decoder
NewDecoder creates a new JSON decoder
Parameters:
- mode: The flag mode
Returns:
- *Decoder: The default decoder
func (Decoder) DecodeReader ¶ added in v0.12.2
DecodeReader decodes the JSON body and stores it in the destination
Parameters:
- reader: The reader to read the body from
- dest: The destination to store the decoded body
Returns:
- error: The error if any
func (Decoder) DecodeRequest ¶ added in v0.12.2
DecodeRequest decodes the JSON request body and stores it in the destination
Parameters:
- request: The HTTP request
- dest: The destination to store the decoded body
Returns:
- error: The error if any
type StreamDecoder ¶ added in v0.11.2
type StreamDecoder struct {
// contains filtered or unexported fields
}
StreamDecoder is the JSON decoder struct
func NewStreamDecoder ¶ added in v0.11.2
func NewStreamDecoder( mode *goflagsmode.Flag, ) *StreamDecoder
NewStreamDecoder creates a new JSON decoder
Parameters:
- mode: The flag mode
- responsesHandler: The HTTP handler to handle errors
Returns:
- *StreamDecoder: The default decoder
func (StreamDecoder) DecodeReader ¶ added in v0.12.2
func (s StreamDecoder) DecodeReader( reader io.Reader, dest interface{}, ) error
DecodeReader decodes a JSON body from a reader into a destination
Parameters:
- reader: The reader to read the body from
- dest: The destination to store the decoded body
Returns:
- error: The error if any
func (StreamDecoder) DecodeRequest ¶ added in v0.12.2
func (s StreamDecoder) DecodeRequest( request *http.Request, dest interface{}, ) error
DecodeRequest decodes a JSON body from an HTTP request into a destination
Parameters:
- request: The HTTP request to read the body from
- dest: The destination to store the decoded body
Returns:
- error: The error if any
Click to show internal directories.
Click to hide internal directories.