Documentation
¶
Index ¶
Constants ¶
View Source
const ( AccessControlAllowCredentialsKey = "Access-Control-Allow-Credentials" AccessControlAllowHeadersKey = "Access-Control-Allow-Headers" AccessControlAllowMethodsKey = "Access-Control-Allow-Methods" AccessControlAllowOriginKey = "Access-Control-Allow-Origin" AccessControlExposeHeadersKey = "Access-Control-Expose-Headers" AccessControlMaxAgeKey = "Access-Control-Max-Age" AccessControlRequestHeadersKey = "Access-Control-Request-Headers" AccessControlRequestMethodKey = "Access-Control-Request-Method" )
Variables ¶
This section is empty.
Functions ¶
func Middleware ¶
func Middleware(ac AccessControl) func(http.Handler) http.Handler
func NewHandler ¶
func NewHandler(next http.Handler, ac AccessControl) http.Handler
Types ¶
type AccessControl ¶
type AccessControl struct {
// AllowCredentials sets the Access-Control-Allow-Credentials response
// header which tells browsers whether to expose the response to the
// frontend JavaScript code.
// When a request's credentials mode is `include`, browsers will only
// expose the response if the Access-Control-Allow-Credentials header value
// is true.
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials
AllowCredentials bool
// AllowHeaders sets the Access-Control-Allow-Headers response header which
// 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.
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers
AllowHeaders []string
// AllowMethods sets the Access-Control-Allow-Methods response header which
// specifies one or more methods allowed when accessing a resource in
// response to a preflight request.
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Methods
AllowMethods []string
// AllowOrigin sets the Access-Control-Allow-Origin response header which
// indicates whether the response can be shared with requesting code from
// the given origin.
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin
AllowOrigin []string
// ExposeHeaders sets the Access-Control-Expose-Headers response header
// which 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.
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers
ExposeHeaders []string
// MaxAge sets the Access-Control-Max-Age response header which 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.
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Max-Age
MaxAge time.Duration
}
AccessControl https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
Click to show internal directories.
Click to hide internal directories.