cors-examples

February 27, 2026 ยท View on GitHub

What is this?

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.

What is the example?

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 or POST, 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.

Which routers are represented?

LibraryCompatibilityPath to example
Chiv5.2+chi=v5/main.go
Echov4.15+echo-v4/main.go
Fiberv2.52+fiber-v2/main.go
Fuegov0.18+fuego/main.go
gorilla/muxv1.8+gorilla-mux/main.go
net/httpv1.22+net-http/main.go