Documentation ¶
Index ¶
Constants ¶
const ( ContentTypeJSON = "application/json; charset=UTF-8" ContentTypePlaintext = "text/plain" ContentTypeCSV = "text/csv" )
Defines some common ContentType strings
Variables ¶
This section is empty.
Functions ¶
func ContentType ¶
func ContentType(w http.ResponseWriter, contentType string)
ContentType is a convience function to set the Content-Type header
Types ¶
type Handler ¶
type Handler struct {
H func(w http.ResponseWriter, r *http.Request) error
}
Handler extends the http.Handler interface and allows handlers to return and error
type HandlerError ¶
HandlerError satisfies the error interface and allows for http handlers to set a specific HTTP Status Code
func (*HandlerError) Error ¶
func (h *HandlerError) Error() string
Error satisfies the error interface, returning the wrapped error
func (*HandlerError) StatusCode ¶
func (h *HandlerError) StatusCode() int
StatusCode returns the configured status code
type RequestParams ¶
type RequestParams struct {
// contains filtered or unexported fields
}
RequestParams represents the query and path parameters of a request
func Params ¶
func Params(r *http.Request) *RequestParams
Params is a helper function that combines URL and query parameters into a single map
func ParamsFromMap ¶
func ParamsFromMap(values map[string][]string) *RequestParams
ParamsFromMap builds a RequestParams from the given map
func (*RequestParams) Get ¶
func (p *RequestParams) Get(k string) (string, bool)
Get returns the requested param, if available
func (*RequestParams) Int ¶
func (p *RequestParams) Int(k string) (int, bool)
Int returns the given parameter casted to int if possible
func (*RequestParams) MaybeInt ¶
func (p *RequestParams) MaybeInt(k string, fallback int) int
MaybeInt returns the given parameter casted to int, or the given fallback if not set or not castable
func (*RequestParams) Require ¶
func (p *RequestParams) Require(required ...string) error
Require ensures all passed keys are in the RequestParams