handler

package
v0.5.8 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilHandler = errors.New("response handler cannot be nil")
)

Functions

func SendInternalServerError

func SendInternalServerError(
	w http.ResponseWriter,
	encoder gonethttpjson.Encoder,
)

SendInternalServerError sends an internal server error response

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) HandleErrorProneResponse

func (d *DefaultHandler) HandleErrorProneResponse(
	w http.ResponseWriter,
	successResponse *gonethttpresponse.Response,
	errorResponse *gonethttpresponse.Response,
)

HandleErrorProneResponse handles the response that may contain an error

func (*DefaultHandler) HandleRequest

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

HandleRequest handles the request

func (*DefaultHandler) HandleRequestAndValidations added in v0.4.10

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

HandleRequestAndValidations handles the request and the validations

func (*DefaultHandler) HandleResponse added in v0.4.4

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

HandleResponse handles the response

func (*DefaultHandler) HandleValidations added in v0.4.10

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

HandleValidations handles the validations

type Handler

type Handler interface {
	HandleRequest(
		w http.ResponseWriter,
		r *http.Request,
		body interface{},
	) error
	HandleValidations(
		w http.ResponseWriter,
		body interface{},
		validatorFn func(body interface{}) (interface{}, error),
	) bool
	HandleRequestAndValidations(
		w http.ResponseWriter,
		r *http.Request,
		body interface{},
		validatorFn func(body interface{}) (interface{}, error),
	) bool
	HandleResponse(
		w http.ResponseWriter,
		response *gonethttpresponse.Response,
	)
	HandleErrorProneResponse(
		w http.ResponseWriter,
		successResponse *gonethttpresponse.Response,
		errorResponse *gonethttpresponse.Response,
	)
}

Handler interface for handling the responses

Jump to

Keyboard shortcuts

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