Documentation ¶
Index ¶
- Variables
- func CORS(next http.Handler) http.Handler
- func CORSWithConfig(next http.Handler, config *CORSConfig) http.Handler
- func DefaultSkipper(res http.ResponseWriter, req *http.Request) bool
- func RemoveTrailingSlash(next http.Handler) http.Handler
- func RequestID(next http.Handler) http.Handler
- func RequestIDWithConfig(next http.Handler, config RequestIDConfig) http.Handler
- type CORSConfig
- type LogOptions
- type LoggingMiddleware
- type RequestIDConfig
- type Skipper
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultCORSConfig is the default CORS middleware config. DefaultCORSConfig = CORSConfig{ Skipper: DefaultSkipper, AllowOrigins: []string{"*"}, AllowMethods: []string{ http.MethodGet, http.MethodHead, http.MethodPut, http.MethodPatch, http.MethodPost, http.MethodDelete, }, } )
var ( // DefaultRequestIDConfig is the default RequestID middleware config. DefaultRequestIDConfig = RequestIDConfig{ Generator: func() string { return "be-" + ksuid.New().String() }, } )
Functions ¶
func CORS ¶
CORS returns a Cross-Origin Resource Sharing (CORS) middleware. See: https://developer.mozilla.org/en/docs/Web/HTTP/Access_control_CORS
func CORSWithConfig ¶
func CORSWithConfig(next http.Handler, config *CORSConfig) http.Handler
CORSWithConfig returns a Cross-Origin Resource Sharing (CORS) middleware. nolint:gocyclo
func DefaultSkipper ¶
func DefaultSkipper(res http.ResponseWriter, req *http.Request) bool
DefaultSkipper returns false which processes the middleware.
func RemoveTrailingSlash ¶
RemoveTrailingSlash returns a root level (before router) middleware which removes a trailing slash from the request URI.
func RequestID ¶
RequestID returns a X-Request-ID middleware. Generate an uuid if request header X-Request-ID is empty. Prefix `be-` means it was generated by server instead of client.
func RequestIDWithConfig ¶
func RequestIDWithConfig(next http.Handler, config RequestIDConfig) http.Handler
RequestIDWithConfig returns a X-Request-ID middleware with config.
Types ¶
type CORSConfig ¶
type CORSConfig struct { // Skipper defines a function to skip middleware. Skipper Skipper // AllowOrigin defines a list of origins that may access the resource. // Optional. Default value []string{"*"}. AllowOrigins []string `yaml:"allow_origins"` // AllowMethods defines a list methods allowed when accessing the resource. // This is used in response to a preflight request. // Optional. Default value DefaultCORSConfig.AllowMethods. AllowMethods []string `yaml:"allow_methods"` // AllowHeaders defines a list of request headers that can be used when // making the actual request. This is in response to a preflight request. // Optional. Default value []string{}. AllowHeaders []string `yaml:"allow_headers"` // AllowCredentials indicates whether or not the response to the request // can be exposed when the credentials flag is true. When used as part of // a response to a preflight request, this indicates whether or not the // actual request can be made using credentials. // Optional. Default value false. AllowCredentials bool `yaml:"allow_credentials"` // ExposeHeaders defines a whitelist headers that clients are allowed to // access. // Optional. Default value []string{}. ExposeHeaders []string `yaml:"expose_headers"` // MaxAge indicates how long (in seconds) the results of a preflight request // can be cached. // Optional. Default value 0. MaxAge int `yaml:"max_age"` }
CORSConfig defines the config for CORS middleware.
type LogOptions ¶
LogOptions logging middleware options
type LoggingMiddleware ¶
type LoggingMiddleware struct {
// contains filtered or unexported fields
}
LoggingMiddleware is a middleware handler that logs the request as it goes in and the response as it goes out.
func NewLogger ¶
func NewLogger(opts ...LogOptions) *LoggingMiddleware
NewLogger returns a new *LoggingMiddleware, yay!
func (*LoggingMiddleware) Middleware ¶
func (m *LoggingMiddleware) Middleware(next http.Handler) http.Handler
Middleware implement mux middleware interface
type RequestIDConfig ¶
type RequestIDConfig struct { // Generator defines a function to generate an ID. // Optional. Default value random.String(32). Generator func() string }
RequestIDConfig defines the config for RequestID middleware.