Documentation ¶
Overview ¶
This is a cors middleware for the gin http framwork and can be used to configure the cors behaviour of your application
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CorsMiddleware ¶
func CorsMiddleware(config Config) gin.HandlerFunc
CORS Middleware for Gin which handles CORS headers and preflight requests needs a cors config
Types ¶
type Config ¶
type Config struct { // All the allowed origins in an array. The default is "*" // The default cannot be used when AllowCredentials is true // [MDN Web Docs] // // [MDN Web Docs]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin AllowedOrigins []string // All the allowed HTTP Methodes. The default is "*" // The default cannot be used when AllowCredentials is true // [MDN Web Docs] // // [MDN Web Docs]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Methods AllowedMethods []string // All the allowed Headers that can be sent from the client. The default is "*" // The default cannot be used when AllowCredentials is true // Note that the Authorization header cannot be wildcarded and needs to be listed explicitly [MDN Web Docs] // // [MDN Web Docs]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers AllowedHeaders []string // The headers which should be readable by the client. The default is "*" // The default cannot be used when AllowCredentials is true // [MDN Web Docs] // // [MDN Web Docs]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers ExposeHeaders []string // If you allow receiving cookies and Authorization headers. The default is false // [MDN Web Docs] // // [MDN Web Docs]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials AllowCredentials bool // The maximum age of your preflight requests. The default is 1 day // [MDN Web Docs] // // [MDN Web Docs]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Max-Age MaxAge time.Duration }
Defines the configuration of your cors middleware
func DefaultConfig ¶
func DefaultConfig() Config
The default config for the cors middleware
Config{ AllowedOrigins: []string{"*"}, AllowedMethods: []string{"*"}, AllowedHeaders: []string{"Authorization", "Conten-Type", "Content-Length"}, ExposeHeaders: []string{"Content-Length"}, AllowCredentials: false, MaxAge: 24 * time.Hour, }
Click to show internal directories.
Click to hide internal directories.