A spec-compliant CORS middleware.
c := corset.NewCorset(corset.CorsetOptions{
AllowedOrigins: origins,
AllowedMethods: methods,
AllowedHeaders: headers,
ExposeHeaders: []string{"X-Powered-By"},
AllowCredentials: true,
})
r := NewRouter() // implements `ServeHTTP`
if err := http.ListenAndServe(":3000", c.Handler(r)); err != nil {
log.Fatal(err)
}
type Corset struct {
}
Corset represents a Corset middleware object.
func NewCorset(opts CorsetOptions) *Corset
NewCorset initializes a new Corset middleware object.
func NewCorsetSensibleDefaults() *Corset
func (c *Corset) Handler(h http.Handler) http.Handler
Handler initializes the Corset middleware and applies the CORS spec, as configured by the consumer, on the request.
type CorsetOptions struct {
AllowedOrigins []string
AllowedMethods []string
AllowedHeaders []string
AllowCredentials bool
UseOptionsPassthrough bool
MaxAge int
ExposeHeaders []string
}
CorsetOptions represents configurable options that are available to the consumer.