Middleware.CORS
Overview
CORS adds Cross-Origin Resource Sharing headers.
If you are coming from Node.js, the closest pattern is cors.
Method on Middleware — call it on a value of that type after constructing or receiving one from a constructor.
Signature
go
func CORS(opts CORSOptions) MiddlewareCompare: Node.js · Standard Go · gox
js
corsgo
func handler(w http.ResponseWriter, r *http.Request) {
// chi or net/http
}go
import "github.com/sahilkhaire/gox/http"
http.CORS(opts)Example
go
import "github.com/sahilkhaire/gox/http"
http.CORS(opts)Tips
Stack Logger, Recover, and Security middleware the way you would morgan + helmet in Express.
Standard library alternative
Use the standard library directly:
go
func handler(w http.ResponseWriter, r *http.Request) {
// chi or net/http
}