handler

package
v0.7.19 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 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,
	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) 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

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) Parse added in v0.6.4

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

Parse decodes and validates the request body

func (*DefaultHandler) ParseWildcard added in v0.6.2

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

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

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
	Parse(
		w http.ResponseWriter,
		r *http.Request,
		dest interface{},
		validatorFn func(body interface{}) (interface{}, error),
	) bool
	GetParameters(
		r *http.Request,
		keys ...string,
	) *map[string]string
	ParseWildcard(
		w http.ResponseWriter,
		r *http.Request,
		wildcardKey string,
		dest interface{},
		toTypeFn func(wildcard 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