Documentation ¶
Overview ¶
Package webmiddleware provides middleware for http Handlers.
Index ¶
- type Authenticator
- type CORSConfig
- type MiddlewareFunc
- func BasicAuth(realm string, authenticator Authenticator) MiddlewareFunc
- func CORS(config CORSConfig) MiddlewareFunc
- func FillContext(fillers ...fillcontext.Filler) MiddlewareFunc
- func Log(logger log.Interface) MiddlewareFunc
- func MaxBody(maxBytes int64) MiddlewareFunc
- func Metadata(keys ...string) MiddlewareFunc
- func ProxyHeaders(config ProxyConfiguration) MiddlewareFunc
- func Recover() MiddlewareFunc
- func Redirect(config RedirectConfiguration) MiddlewareFunc
- func RequestID() MiddlewareFunc
- func RequestURL() MiddlewareFunc
- func SecurityHeaders() MiddlewareFunc
- type ProxyConfiguration
- type RedirectConfiguration
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Authenticator ¶
type Authenticator interface { // Authenticate the user with the given password and return true if successful. // An error may be returned if an internal error occurred. Authenticate(username, password string) (ok bool, err error) }
Authenticator is the interface the Basic Auth middleware uses to authenticate users.
func AuthUser ¶
func AuthUser(username, password string) Authenticator
AuthUser is the same as AuthUsers, but for a single user.
func AuthUsers ¶
func AuthUsers(usernamesPasswords map[string]string) Authenticator
AuthUsers authenticates users with the given map[username]password.
type CORSConfig ¶
type CORSConfig struct { AllowedHeaders []string AllowedMethods []string AllowedOrigins []string ExposedHeaders []string MaxAge int AllowCredentials bool }
CORSConfig is the configuration for the CORS middleware.
type MiddlewareFunc ¶
MiddlewareFunc is a function that acts as middleware for http Handlers.
func BasicAuth ¶
func BasicAuth(realm string, authenticator Authenticator) MiddlewareFunc
BasicAuth returns a middleware that authenticates users with Basic Auth.
func CORS ¶
func CORS(config CORSConfig) MiddlewareFunc
CORS returns a middleware that handles Cross-Origin Resource Sharing.
func FillContext ¶
func FillContext(fillers ...fillcontext.Filler) MiddlewareFunc
FillContext returns a middleware that fills global context into a call context.
func Log ¶
func Log(logger log.Interface) MiddlewareFunc
Log returns a middleware that logs requests. If logger is nil, the logger will be extracted from the context.
func MaxBody ¶
func MaxBody(maxBytes int64) MiddlewareFunc
MaxBody returns a middleware that limits the maximum body of requests.
func Metadata ¶
func Metadata(keys ...string) MiddlewareFunc
Metadata returns a middleware that sets gRPC metadata from the request headers.
func ProxyHeaders ¶
func ProxyHeaders(config ProxyConfiguration) MiddlewareFunc
ProxyHeaders processes proxy headers for trusted proxies.
func Redirect ¶
func Redirect(config RedirectConfiguration) MiddlewareFunc
Redirect returns a middleware that redirects requests if they don't already match the configuration.
func RequestID ¶
func RequestID() MiddlewareFunc
RequestID returns a middleware that inserts a request ID into each request.
func RequestURL ¶
func RequestURL() MiddlewareFunc
RequestURL populates (*http.Request).URL with the scheme and host.
func SecurityHeaders ¶
func SecurityHeaders() MiddlewareFunc
SecurityHeaders returns a middleware that inserts security headers into each response.
type ProxyConfiguration ¶
ProxyConfiguration is the configuration for the ProxyHeaders middleware.
func (*ProxyConfiguration) ParseAndAddTrusted ¶
func (c *ProxyConfiguration) ParseAndAddTrusted(cidrs ...string) error
ParseAndAddTrusted parses a list of CIDRs and adds them to the list of trusted ranges.
type RedirectConfiguration ¶
type RedirectConfiguration struct { Scheme func(string) string HostName func(string) string Port func(uint) uint Path func(string) string Code int }
RedirectConfiguration is the configuration for the Redirect middleware. If any of Scheme, HostName, Port, Path returns a different value than the argument passed to it, the middleware will redirect with the configured Code.