Documentation ¶
Overview ¶
Package cors provides an alternative CORS implementation for Martini.
It relies on the Route.MethodsFor to provide Access-Control-Allow-Methods.
Due to the modularity of Martini, Routes is not available in Middleware handlers so both a Middleware and NotFound handler are required.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var StandardHeaders = map[string]string{
"Access-Control-Max-Age": "86000",
"Access-Control-Allow-Headers": "Content-Type, Origin, Authorization",
"Access-Control-Expose-Headers": "Content-Length",
}
StandardHeaders are an example.
Functions ¶
func RealNotFound ¶
RealNotFound provides an alternative to Martini's inbuilt handler as using a CORS NotFound means we have to handle it ourselves.
Types ¶
type Cors ¶
type Cors struct { // Allowed origins is now provided through an interface // for more flexibility Origins Sites // CORS headers. Please use write mutex if updating while live. HeadersMutex sync.RWMutex // Can use cors.StandardHeaders or provide your own Headers map[string]string // Default is to return 403 if Origin not a match. Set to true to disable. Tolerant bool // This is a key to allow overriding Origin with an X-Origin for tools // that don't support setting Origin headers eg Postman on a chromebook. // Not for production use. Header is called X-Dev DevKey string }
Cors type allows configuration of CORS handling
func (*Cors) MiddleWare ¶
Middleware checks the Origin header on requests and adds appropriate CORS headers to the response.
Click to show internal directories.
Click to hide internal directories.