Documentation
¶
Index ¶
- Variables
- type DefaultHandler
- func (d DefaultHandler) Decode(w http.ResponseWriter, r *http.Request, dest interface{}) error
- func (d DefaultHandler) GetParameters(r *http.Request, keys ...string) map[string]string
- func (d DefaultHandler) HandleError(w http.ResponseWriter, err error)
- func (d DefaultHandler) HandleResponse(w http.ResponseWriter, response gonethttpresponse.Response)
- func (d DefaultHandler) Parse(w http.ResponseWriter, r *http.Request, dest interface{}, ...) bool
- func (d DefaultHandler) ParseWildcard(w http.ResponseWriter, r *http.Request, wildcardKey string, dest interface{}, ...) bool
- func (d DefaultHandler) Validate(w http.ResponseWriter, body interface{}, ...) bool
- type Handler
- type ToTypeFn
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
Parameters:
- mode: The flag mode
- jsonEncoder: The JSON encoder
- jsonDecoder: The JSON 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
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 govalidatorstructmappervalidator.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 govalidatorstructmappervalidator.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 govalidatorstructmappervalidator.ValidateFn,
) bool
Parse(
w http.ResponseWriter,
r *http.Request,
dest interface{},
validatorFn govalidatorstructmappervalidator.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
Click to show internal directories.
Click to hide internal directories.