This repository is a collection of examples that illustrate how to use
github.com/jub0bs/cors, a principled CORS middleware library,
in conjunction with net/http
and popular third-party routers
for Go.
The example invariably consists in creating a CORS middleware that
- allows anonymous access from Web origin
https://example.com
, - with requests whose method is either
GET
orPOST
, and - (optionally) with request header
Authorization
,
and applying the middleware in question to all the resources accessible
under an /api/
path.
In addition, a /hello
path is left unconfigured for CORS.
Library | Compatibility | Path to example |
---|---|---|
Chi | v5.1+ | chi=v5/main.go |
Echo | v4.11+ | echo-v4/main.go |
Fiber | v2.52+ | fiber-v2/main.go |
gorilla/mux | v1.8+ | gorilla-mux/main.go |
net/http | v1.22+ | net-http/main.go |