Documentation ¶
Index ¶
- func Chain(h http.Handler, adapters ...Adapter) http.Handler
- func ChainFunc(h http.HandlerFunc, adapters ...Adapter) http.Handler
- func Forbidden(w http.ResponseWriter, r *http.Request)
- func GetPageLimit(r *http.Request) int
- func GetPageSkip(r *http.Request) int
- func NoRobots(w http.ResponseWriter, r *http.Request)
- type Adapter
- func Benchmark() Adapter
- func CORS(age int, origins ...string) Adapter
- func Enabled(enabled bool, opts ...interface{}) Adapter
- func Keyed(key string, opts ...interface{}) Adapter
- func Paged(defaultLimit string, opts ...interface{}) Adapter
- func Recaptcha(key string, opts ...interface{}) Adapter
- func RestrictOrigin(origins []string, opts ...interface{}) Adapter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChainFunc ¶
func ChainFunc(h http.HandlerFunc, adapters ...Adapter) http.Handler
ChainFunc chains a http.HandlerFunc with the given adapater.
func Forbidden ¶ added in v1.0.1
func Forbidden(w http.ResponseWriter, r *http.Request)
Forbidden returns a "403 forbidded" error.
func GetPageLimit ¶ added in v1.0.2
GetPageLimit returns the number of elements per page aka limit of the Paged() Adapater. To use this funktion the Paged() adapter need to be chained in.
func GetPageSkip ¶ added in v1.0.2
GetPageSkip returns the element offset aka skip of the Paged() Adapater. To use this funktion the Paged() adapter need to be chained in.
Types ¶
type Adapter ¶
Adapter is a function which implements a middleware handler.
func Benchmark ¶ added in v1.0.2
func Benchmark() Adapter
Benchmark logs the exection time of each request using logrus. In order to work correctly this Adapter should be the first Adapter in the chain.
func Keyed ¶
Keyed restricts the execution of fn() to requests which have the query parameter "key" matched with the user supplied key.
func Paged ¶ added in v1.0.2
Paged parses the limit and skip parameter and stores it to the requests context.
func Recaptcha ¶ added in v1.0.2
Recaptcha verifies the given recaptcha response. If the verification failes the processing of the request is canceled. If the key parameter is empty, the captcha check is bypassed.
func RestrictOrigin ¶ added in v1.0.2
RestrictOrigin prevents further processing if the request origin is not on the origins list.