handler

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2025 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilHandler = errors.New("handler cannot be nil")
	ErrNilRequest = errors.New("request cannot be nil")
)
View Source
var (
	ErrCodeValidationFailed      *string
	ErrCodeWildcardParsingFailed *string
	ErrCodeNilResponse           *string
	ErrCodeRequestFatalError     *string
)

Functions

This section is empty.

Types

type DefaultHandler

type DefaultHandler struct {
	// contains filtered or unexported fields
}

DefaultHandler struct

func NewDefaultHandler

func NewDefaultHandler(
	mode *goflagsmode.Flag,
	encoder gonethttpresponse.Encoder,
	decoder gonethttprequest.Decoder,
) (*DefaultHandler, error)

NewDefaultHandler creates a new default request handler

Parameters:

  • mode: The flag mode
  • encoder: The encoder
  • decoder: The decoder

Returns:

  • *DefaultHandler: The default handler
  • error: The error if any

func (DefaultHandler) Decode added in v0.5.27

func (d DefaultHandler) Decode(
	w http.ResponseWriter,
	r *http.Request,
	dest interface{},
) error

Decode decodes the request body into the destination

Parameters:

  • w: The HTTP response writer
  • r: The HTTP request
  • dest: The destination to decode the request body into

Returns:

  • error: The error if any

func (DefaultHandler) GetParameters added in v0.6.1

func (d DefaultHandler) GetParameters(
	r *http.Request,
	keys ...string,
) map[string]string

GetParameters gets the parameters from the request

Parameters:

  • r: The HTTP request
  • keys: The keys of the parameters to get

Returns:

  • map[string]string: The parameters map

func (DefaultHandler) HandleError added in v0.5.27

func (d DefaultHandler) HandleError(
	w http.ResponseWriter,
	err error,
)

HandleError handles the error response

Parameters:

  • w: The HTTP response writer
  • err: The error to handle

func (DefaultHandler) HandleResponse added in v0.4.4

func (d DefaultHandler) HandleResponse(
	w http.ResponseWriter,
	response gonethttpresponse.Response,
)

HandleResponse handles the response

Parameters:

  • w: The HTTP response writer
  • response: The response to handle

func (DefaultHandler) Parse added in v0.6.4

func (d DefaultHandler) Parse(
	w http.ResponseWriter,
	r *http.Request,
	dest interface{},
	validatorFn govalidatormappervalidator.ValidateFn,
) bool

Parse decodes and validates the request body

Parameters:

  • w: The HTTP response writer
  • r: The HTTP request
  • dest: The destination to decode the request body into
  • validatorFn: The validator function

Returns:

  • bool: True if the request body is valid, false otherwise

func (DefaultHandler) ParseWildcard added in v0.6.2

func (d DefaultHandler) ParseWildcard(
	w http.ResponseWriter,
	r *http.Request,
	wildcardKey string,
	dest interface{},
	toTypeFn ToTypeFn,
) bool

ParseWildcard parses the wildcard from the request and stores it in the destination

Parameters:

  • w: The HTTP response writer
  • r: The HTTP request
  • wildcardKey: The key of the wildcard to parse
  • dest: The destination to store the parsed wildcard
  • toTypeFn: The function to convert the wildcard value to the desired type

Returns:

  • bool: True if the wildcard was parsed successfully, false otherwise

func (DefaultHandler) Validate added in v0.5.27

func (d DefaultHandler) Validate(
	w http.ResponseWriter,
	body interface{},
	validatorFn govalidatormappervalidator.ValidateFn,
) bool

Validate validates the request body

Parameters:

  • w: The HTTP response writer
  • body: The request body to validate
  • validatorFn: The validator function

Returns:

  • bool: True if the request body is valid, false otherwise

type Handler

type Handler interface {
	Decode(
		w http.ResponseWriter,
		r *http.Request,
		dest interface{},
	) error
	Validate(
		w http.ResponseWriter,
		body interface{},
		validatorFn govalidatormappervalidator.ValidateFn,
	) bool
	Parse(
		w http.ResponseWriter,
		r *http.Request,
		dest interface{},
		validatorFn govalidatormappervalidator.ValidateFn,
	) bool
	GetParameters(
		r *http.Request,
		keys ...string,
	) map[string]string
	ParseWildcard(
		w http.ResponseWriter,
		r *http.Request,
		wildcardKey string,
		dest interface{},
		toTypeFn ToTypeFn,
	) bool
	HandleResponse(
		w http.ResponseWriter,
		response gonethttpresponse.Response,
	)
	HandleError(
		w http.ResponseWriter,
		err error,
	)
}

Handler interface for handling the requests

type ToTypeFn added in v0.10.0

type ToTypeFn func(wildcard string, dest interface{}) error

ToTypeFn type for the wildcard to type function

Jump to

Keyboard shortcuts

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