Documentation
¶
Overview ¶
Package cors provides a CORS middleware.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultAllowMethods = []string{ http.MethodHead, http.MethodGet, http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete, }
DefaultAllowMethods is the default allowed methods, which is set as the value of the http header "Access-Control-Allow-Methods".
Functions ¶
func CORS ¶
func CORS(config Config) middleware.MiddlewareFunc
CORS returns a new middleware named "cors", which implements HTTP CORS protocol. see https://fetch.spec.whatwg.org/#http-cors-protocol.
Types ¶
type Config ¶
type Config struct { // AllowOrigin defines a list of origins that may access the resource. // // Optional. Default: []string{"*"}. AllowOrigins []string `json:"allowOrigins" yaml:"allowOrigins"` // AllowHeaders indicates a list of request headers used in response to // a preflight request to indicate which HTTP headers can be used when // making the actual request. This is in response to a preflight request. // // Optional. Default: []string{}. AllowHeaders []string `json:"allowHeaders" yaml:"allowHeaders"` // AllowMethods indicates methods allowed when accessing the resource. // This is used in response to a preflight request. // // Optional. Default: DefaultAllowMethods. AllowMethods []string `json:"allowMethods" yaml:"allowMethods"` // ExposeHeaders indicates a server whitelist headers that browsers are // allowed to access. This is in response to a preflight request. // // Optional. Default: []string{}. ExposeHeaders []string `json:"exposeHeaders" yaml:"exposeHeaders"` // 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: false. AllowCredentials bool `json:"allowCredentials" yaml:"allowCredentials"` // MaxAge indicates how long (in seconds) the results of a preflight request // can be cached. // // Optional. Default: 0. MaxAge int `json:"maxAge" yaml:"maxAge"` }
Config is used to configure the CORS middleware.
Click to show internal directories.
Click to hide internal directories.