Documentation
¶
Overview ¶
Package middleware provides multiple middlewares, useful for any HTTP service. These middlewares are not specific to any application, and are made to be as reusable and idiomatic as possible. Compatibility is guaranteed for `net/http`, however these middlewares should be compatible with any third-party package which conforms to the standard library's APIs.
Index ¶
- func Compose(h http.Handler, m ...Middleware) http.Handler
- func Etag(next http.Handler) http.Handler
- func Recover(next http.Handler) http.Handler
- func SetHeader(key, value string) func(next http.Handler) http.Handler
- type AppHeadersOptions
- type AuthOptions
- type EtagWriter
- type LoggerOptions
- type Middleware
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compose ¶
func Compose(h http.Handler, m ...Middleware) http.Handler
Compose adds middleware handlers to a given handler. Middleware handlers are ordered from first to last.
Types ¶
type AppHeadersOptions ¶ added in v0.23.0
AppHeaders holds app specific header values.
type AuthOptions ¶ added in v0.23.0
type AuthOptions struct {
WhiteList []string
APIKeyName string
SecretKey string
ErrorMessage string
}
AuthOptions holds the necessary values for the authentication middleware
type EtagWriter ¶ added in v0.1.1
type EtagWriter struct {
http.ResponseWriter
// contains filtered or unexported fields
}
EtagWriter provides a ResponseWriter which holds info needed for verifying etags.
func NewEtagWriter ¶ added in v0.23.0
func NewEtagWriter(w http.ResponseWriter) *EtagWriter
NewEtagWriter returns an EtagWriter with a wrapped ResponseWriter.
func (*EtagWriter) ClientEtag ¶ added in v0.23.0
func (e *EtagWriter) ClientEtag(t string) *EtagWriter
ClientEtag sets the requested ETag.
type LoggerOptions ¶ added in v0.23.0
LoggerOptions holds all logger middleware options.
type Middleware ¶
Middleware aliases the function type for all middleware.
func AppHeaders ¶
func AppHeaders(opts AppHeadersOptions) Middleware
AppHeaders adds more app-specific headers to the response.
func Auth ¶
func Auth(opts AuthOptions) Middleware
Auth handles authenticating requests. Authentication is driven by an API key query parameter.
func Logger ¶
func Logger(opts LoggerOptions) Middleware
Logger outputs general information about requests.
func SecureDefault ¶ added in v0.23.0
func SecureDefault() Middleware
SecureDefault is similar to Secure, but provides sane security defaults, without requiring options to be provided.