request

package
v0.14.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2025 License: GPL-3.0 Imports: 7 Imported by: 0

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
	ErrCodeNilDecoder                 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")
	ErrNilDecoder          = errors.New("decoder cannot be nil")
)

Functions

func BodyDecodeErrorHandler added in v0.12.5

func BodyDecodeErrorHandler(
	err error,
) error

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

func CheckContentType(r *http.Request) bool

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

type Decoder

type Decoder interface {
	Decode(
		body any,
		dest any,
	) error
	DecodeReader(
		reader io.Reader,
		dest any,
	) error
	DecodeRequest(
		r *http.Request,
		dest any,
	) error
}

Decoder interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL