This is package is wrapper based on rs/cors package made for minima.
package main
import (
"github.com/gominima/cors"
"github.com/gominima/minima"
)
func main() {
app := minima.New()
crs := cors.New()
app.Get("/", func(res *minima.Response, req *minima.Request) {
res.OK().Send("Hello World")
res.CloseConn()
})
app.Use(crs.AllowAll())
app.Listen(":3000")
}
$ curl -D - -H 'Origin: http://abc.com' http://localhost:3000/
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Vary: Origin
Date: Wed, 09 Feb 2022 03:42:42 GMT
Content-Length: 11
Content-Type: text/plain; charset=utf-8
Using your own custom cors config is as simple as it gets thanks to rs/cors
app := minima.New()
crs := cors.New()
c := crs.NewCors(cors.Options{
AllowedOrigins: []string{"http://ur_url.com"},
AllowCredentials: true,
// Enable Debugging for testing, consider disabling in production
Debug: true,
})
app.Use(c())