The Cors module enhances github.com/gin-contrib/cors
with more convenient methods and configuration.
This project has been developped by the Aloe team and is now open source.
The cors module offers:
- A
Conf
structure withyaml
andmapstructure
tags - Builder methods for the convenient creation of a new middleware
- Default values to reduce code repetition in your projects
- Easy integration because it embed a native
github.com/gin-contrib/cors
The default middleware provides an open CORS configuration that can be useful during the development process.
builder := new(cors.Builder)
conf := builder.New().Build()
Enhance the security of your Gin API by specifying allowed origins in addition to the default configuration.
builder := new(cors.Builder)
conf := builder.New().WithOrigins("http://localhost:8080").Build()
Use the cors middleware on your gin endpoints.
Router := gin.New()
corsBuilder := new(cors.Builder)
Router.Use(cors.Middleware(corsBuilder.New().WithOrigins("http://localhost:8080").Build()))
Use it with default configuration.
Router := gin.New()
Router.Use(cors.Middleware(nil))
Use if with the Conf
struct
Router := gin.New()
conf := &cors.Conf{
// your parsed configuration
}
corsBuilder := new(cors.Builder)
Router.Use(cors.Middleware(corsBuilder.NewFromConf(conf).Build()))
This section will be added soon.
Client is released under the MIT license. See LICENSE.txt.