handler

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2025 License: GPL-3.0 Imports: 7 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")
	ErrParameterNotFound = "parameter not found: '%s'"
)
View Source
var (
	ErrCodeParameterNotFound      *string
	ErrCodeParameterParsingFailed *string
	ErrCodeValidationFailed       *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,
	jsonEncoder gonethttpjson.Encoder,
	jsonDecoder gonethttpjson.Decoder,
) (*DefaultHandler, error)

NewDefaultHandler creates a new default request handler

func (*DefaultHandler) Decode added in v0.5.27

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

Decode decodes the request body into the destination

func (*DefaultHandler) DecodeAndValidate added in v0.5.27

func (d *DefaultHandler) DecodeAndValidate(
	w http.ResponseWriter,
	r *http.Request,
	body interface{},
	validatorFn func(body interface{}) (interface{}, error),
) bool

DecodeAndValidate decodes and validates the request body

func (*DefaultHandler) GetParameters added in v0.6.1

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

GetParameters gets the parameters from the request

func (*DefaultHandler) HandleError added in v0.5.27

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

HandleError handles the error response

func (*DefaultHandler) HandleResponse added in v0.4.4

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

HandleResponse handles the response

func (*DefaultHandler) ParseParameter added in v0.6.1

func (d *DefaultHandler) ParseParameter(
	w http.ResponseWriter,
	parameter string,
	dest interface{},
	toTypeFn func(parameter string, dest interface{}) error,
) bool

ParseParameter parses the parameter

func (*DefaultHandler) Validate added in v0.5.27

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

Validate validates the request body

type Handler

type Handler interface {
	Decode(
		w http.ResponseWriter,
		r *http.Request,
		dest interface{},
	) error
	Validate(
		w http.ResponseWriter,
		body interface{},
		validatorFn func(body interface{}) (interface{}, error),
	) bool
	DecodeAndValidate(
		w http.ResponseWriter,
		r *http.Request,
		dest interface{},
		validatorFn func(body interface{}) (interface{}, error),
	) bool
	GetParameters(
		w http.ResponseWriter,
		r *http.Request,
		keys ...string,
	) (*map[string]string, bool)
	ParseParameter(
		w http.ResponseWriter,
		parameter string,
		dest interface{},
		toTypeFn func(parameter string, dest interface{}) error,
	) bool
	HandleResponse(
		w http.ResponseWriter,
		response gonethttpresponse.Response,
	)
	HandleError(
		w http.ResponseWriter,
		err error,
	)
}

Handler interface for handling the requests

Jump to

Keyboard shortcuts

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