Categorygithub.com/go-http-utils/cors
modulepackage
0.0.0-20170207144901-58c2accd8747
Repository: https://github.com/go-http-utils/cors.git
Documentation: pkg.go.dev

# README

cors

Build Status Coverage Status

CORS middleware for Go.

Installation

go get -u github.com/go-http-utils/cors

Documentation

API documentation can be found here: https://godoc.org/github.com/go-http-utils/cors

Usage

import (
  "github.com/go-http-utils/cors"
)
mux := http.NewServeMux()
mux.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
  res.Write([]byte("Hello World"))
})

http.ListenAndServe(":8080", cors.Handler(mux))

# Functions

Handler wraps the http.Handler with CORS support.
SetAllowHeaders configures the Access-Control-Allow-Headers CORS header.
SetAllowOrigin configures the Access-Control-Allow-Origin CORS header.
SetAllowOriginValidator configures the Access-Control-Allow-Origin CORS header by run the validator function `func(*http.Request) string`.
SetCredentials configures the Access-Control-Allow-Credentials CORS header.
SetExposeHeaders configures the Access-Control-Expose-Headers CORS header.
SetMaxAge configures the Access-Control-Max-Age CORS header (in seconds).
SetMethods configures the Access-Control-Allow-Methods CORS header.

# Constants

Version is this package's version.

# Type aliases

Option returns a configuration func to configurate the CORS middleware.