Documentation ¶
Index ¶
- func GetURLParamString(r *http.Request, param string) (string, error)
- func GetURLParamUint(r *http.Request, param string) (uint, error)
- func HandleAPIError(l *zerolog.Logger, alerter hatcheterrors.Alerter, w http.ResponseWriter, ...)
- type Decoder
- type DefaultDecoder
- type DefaultRequestDecoderValidator
- func (j *DefaultRequestDecoderValidator) DecodeAndValidate(w http.ResponseWriter, r *http.Request, v interface{}) (ok bool)
- func (j *DefaultRequestDecoderValidator) DecodeAndValidateNoWrite(r *http.Request, v interface{}) error
- func (j *DefaultRequestDecoderValidator) DecodeAndValidateQueryOnly(w http.ResponseWriter, r *http.Request, v interface{}) (ok bool)
- type DefaultResultWriter
- type ErrorOpts
- type RequestDecoderValidator
- type ResultWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetURLParamString ¶
GetURLParamString returns a specific URL parameter as a string using chi.URLParam. It returns an internal server error if the URL parameter is not found.
func GetURLParamUint ¶
GetURLParamUint returns a URL parameter as a uint. It returns an internal server error if the URL parameter is not found.
func HandleAPIError ¶
func HandleAPIError( l *zerolog.Logger, alerter hatcheterrors.Alerter, w http.ResponseWriter, r *http.Request, err error, writeErr bool, )
Types ¶
type Decoder ¶
type Decoder interface { // Decode accepts a target struct, a reader for the request body, and a URL // for the request endpoint Decode(s interface{}, r *http.Request) error // DecodeQueryOnly is Decode but only looks at the query parameters DecodeQueryOnly(s interface{}, r *http.Request) error }
Decoder populates a request form from the request body and URL.
func NewDefaultDecoder ¶
func NewDefaultDecoder() Decoder
NewDefaultDecoder returns an implementation of Decoder that uses `json` and `gorilla/schema`.
type DefaultDecoder ¶
type DefaultDecoder struct {
// contains filtered or unexported fields
}
DefaultDecoder decodes the request body with `json` and the URL query params with gorilla/schema,
func (*DefaultDecoder) Decode ¶
func (d *DefaultDecoder) Decode( s interface{}, r *http.Request, ) error
Decode reads the request and populates the target request object.
func (*DefaultDecoder) DecodeQueryOnly ¶
func (d *DefaultDecoder) DecodeQueryOnly( s interface{}, r *http.Request, ) error
Decode reads the request and populates the target request object.
type DefaultRequestDecoderValidator ¶
type DefaultRequestDecoderValidator struct {
// contains filtered or unexported fields
}
func (*DefaultRequestDecoderValidator) DecodeAndValidate ¶
func (j *DefaultRequestDecoderValidator) DecodeAndValidate( w http.ResponseWriter, r *http.Request, v interface{}, ) (ok bool)
func (*DefaultRequestDecoderValidator) DecodeAndValidateNoWrite ¶
func (j *DefaultRequestDecoderValidator) DecodeAndValidateNoWrite( r *http.Request, v interface{}, ) error
func (*DefaultRequestDecoderValidator) DecodeAndValidateQueryOnly ¶
func (j *DefaultRequestDecoderValidator) DecodeAndValidateQueryOnly( w http.ResponseWriter, r *http.Request, v interface{}, ) (ok bool)
type DefaultResultWriter ¶
type DefaultResultWriter struct {
// contains filtered or unexported fields
}
default generalizes response codes for common operations (http.StatusOK, http.StatusCreated, etc)
func (*DefaultResultWriter) WriteResult ¶
func (j *DefaultResultWriter) WriteResult(w http.ResponseWriter, r *http.Request, v interface{})
type RequestDecoderValidator ¶
type RequestDecoderValidator interface { DecodeAndValidate(w http.ResponseWriter, r *http.Request, v interface{}) bool DecodeAndValidateQueryOnly(w http.ResponseWriter, r *http.Request, v interface{}) bool DecodeAndValidateNoWrite(r *http.Request, v interface{}) error }
func NewDefaultRequestDecoderValidator ¶
func NewDefaultRequestDecoderValidator( logger *zerolog.Logger, alerter errors.Alerter, ) RequestDecoderValidator
type ResultWriter ¶
type ResultWriter interface {
WriteResult(w http.ResponseWriter, r *http.Request, v interface{})
}
func NewDefaultResultWriter ¶
func NewDefaultResultWriter( logger *zerolog.Logger, alerter hatcheterrors.Alerter, ) ResultWriter