Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Chain ¶
func Chain(handler http.HandlerFunc, m ...Middleware) http.HandlerFunc
Chain makes it easy to chain a series of middleware to a handler. Reference: https://medium.com/@chrisgregory_83433/chaining-middleware-in-go-918cfbc5644d
Types ¶
type Middleware ¶
type Middleware interface {
Handle(handler http.HandlerFunc) http.HandlerFunc
}
Middleware represents middleware that may help in filtering HTTP requests.
type NotFoundMiddleware ¶
type NotFoundMiddleware struct {
URLPattern string
}
NotFoundMiddleware checks if the
func NewNotFoundMiddleware ¶
func NewNotFoundMiddleware(pattern string) NotFoundMiddleware
NewNotFoundMiddleware returns a new instance of NotFoundMiddleware
func (NotFoundMiddleware) Handle ¶
func (nfm NotFoundMiddleware) Handle(handler http.HandlerFunc) http.HandlerFunc
Handle checks if the request's path matches URLPattern
type PostFormValidator ¶
type PostFormValidator struct {
VisualError bool
}
PostFormValidator verifies if a request has method POST and content-type "application/x-www-form-urlencoded". This is turned into a middleware since it is a common task in OA2B.
VisualError: boolean which determines whether to present a visual (HTML) or textual (JSON) error in case the request doesn't satisfy the above conditions
func NewPostFormValidator ¶
func NewPostFormValidator(visualError bool) PostFormValidator
NewPostFormValidator returns a new instance of PostFormValidator
func (PostFormValidator) Handle ¶
func (pfv PostFormValidator) Handle(handler http.HandlerFunc) http.HandlerFunc
Handle implements the Middleware interface and performs the above mentioned job
type RateLimiter ¶
type RateLimiter struct {
Policies []RatePolicy
}
RateLimiter is an implementation of Middleware. It holds a list of policies that are checked when the CheckLimit method is invoked.
func (RateLimiter) Handle ¶
func (rl RateLimiter) Handle(handler http.HandlerFunc) http.HandlerFunc
Handle checks if the client is within the limits enforced by the policies and returns the appropriate boolean value.
type RatePolicy ¶
type RatePolicy struct { Route string `json:"route"` Limit int `json:"limit"` Minutes int `json:"minutes"` }
RatePolicy represents the rate limiting policy for a specific route.
Route: the server route to apply the policy to Limit: the number of API calls allowed Minutes: the duration in minutes over which 'Limit' is imposed