cors - ActiveState ActiveGo 1.8

Package cors

import ""

Overview ▾

Package cors contains filters to handle CORS related requests defined from


DefaultAllowOrigin sets Access-Control-Allow-Origin when not configured.

const DefaultAllowOrigin = "*"

func Get

func Get(origin string, next http.Handler) http.Handler

Get implements a simple read-only access control policy handling preflight and normal requests with a cache age of 10 minutes for preflight requests. Methods other than HEAD, OPTIONS, GET will return 405.

The origin parameter should be the case-insentive fully qualified origin domain to match or '*' to match any domain.

func Middleware

func Middleware(cfg Config) func(http.Handler) http.Handler

Middleware returns a middleware that applies Config to the request.

type Config

Config parameterizes CORS behavior.

type Config struct {
    // AllowOrigin transforms a request into the Access-Control-Allow-Origin
    // header, default is full access "*".
    AllowOrigin func(*http.Request) string