Documentation
¶
Index ¶
- Variables
- func CORS() func(ctx mojito.Context, next func() error) error
- func CORSWithConfig(config CORSConfig) func(ctx mojito.Context, next func() error) error
- func Compression(ctx mojito.Context, next func() error) (err error)
- func Logging(ctx mojito.Context, next func() error) (err error)
- func RequestLogger(ctx mojito.Context, next func() error) (err error)
- type CORSConfig
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // CORSDefault is the default CORS config. CORSDefault = CORSConfig{ AllowOrigins: []string{"*"}, AllowMethods: []string{http.MethodGet, http.MethodHead, http.MethodPut, http.MethodPatch, http.MethodPost, http.MethodDelete}, AllowHeaders: []string{}, AllowCredentials: false, ExposeHeaders: []string{}, } )
Functions ¶
func CORS ¶
CORS provides a simple middleware implementation that will handle CORS requests using the default config
func CORSWithConfig ¶
func CORSWithConfig(config CORSConfig) func(ctx mojito.Context, next func() error) error
CORSWithConfig provides a simple middleware implementation that will handle CORS requests
func Compression ¶
Compression compresses the http response if supported by the client.
Types ¶
type CORSConfig ¶
type CORSConfig struct {
// The Access-Control-Allow-Origin response header indicates whether the response can be
// shared with requesting code from the given origin.
//
// Optional. Default value []string{"*"}.
//
// See also: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin
AllowOrigins []string
// The Access-Control-Allow-Methods response header specifies one or more methods allowed when
// accessing a resource in response to a preflight request.
//
// Optional. Default value "GET,POST,HEAD,PUT,DELETE,PATCH"
//
// See also: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Methods
AllowMethods []string
// The Access-Control-Allow-Headers response header is used in response to a preflight request which includes
// the Access-Control-Request-Headers to indicate which HTTP headers can be used during the actual request.
//
// Optional. Default value []string{}.
//
// See also: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers
AllowHeaders []string
// The Access-Control-Allow-Credentials response header tells browsers whether to expose the response
// to the frontend JavaScript code when the request's credentials mode (Request.credentials) is include.
//
// Optional. Default value false.
//
// See also: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials
AllowCredentials bool
// The Access-Control-Expose-Headers response header allows a server to indicate which response headers
// should be made available to scripts running in the browser, in response to a cross-origin request.
//
// Optional. Default value []string{}.
//
// See also: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers
ExposeHeaders []string `yaml:"expose_headers"`
// The Access-Control-Max-Age response header indicates how long the results of a preflight request
// (that is the information contained in the Access-Control-Allow-Methods and Access-Control-Allow-Headers headers)
// can be cached.
//
// Optional. Default value 0.
//
// See also: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Max-Age
MaxAge int
}
Click to show internal directories.
Click to hide internal directories.