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
GETorPOST, 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.2+ | chi=v5/main.go |
| Echo | v4.13+ | 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 |