cors

package module
v0.0.0-...-3ddac6d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2019 License: MIT Imports: 4 Imported by: 0

README

cors

Cross-Origin Resource Sharing(CORS) for go route

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(options ...Option) route.MiddlewareFunc

New returns a CORS middleware.

Types

type Option

type Option func(*Options)

func AllowCredentials

func AllowCredentials(allowCredentials bool) Option

func AllowHeaders

func AllowHeaders(allowHeaders []string) Option

func AllowMethods

func AllowMethods(allowMethods []string) Option

func AllowOrigins

func AllowOrigins(allowOrigins []string) Option

func ExposeHeaders

func ExposeHeaders(exposeHeaders []string) Option

func MaxAge

func MaxAge(maxAge int) Option

func Skipper

func Skipper(skipper route.Skipper) Option

type Options

type Options struct {
	// Skipper defines a function to skip middleware.
	Skipper route.Skipper

	// AllowOrigin defines a list of origins that may access the resource.
	// Optional. Default value []string{"*"}.
	AllowOrigins []string `yaml:"allow_origins"`

	// AllowMethods defines a list methods allowed when accessing the resource.
	// This is used in response to a preflight request.
	// Optional. Default value DefaultCORSConfig.AllowMethods.
	AllowMethods []string `yaml:"allow_methods"`

	// AllowHeaders defines a list of request headers that can be used when
	// making the actual request. This in response to a preflight request.
	// Optional. Default value []string{}.
	AllowHeaders []string `yaml:"allow_headers"`

	// AllowCredentials indicates whether or not the response to the request
	// can be exposed when the credentials flag is true. When used as part of
	// a response to a preflight request, this indicates whether or not the
	// actual request can be made using credentials.
	// Optional. Default value false.
	AllowCredentials bool `yaml:"allow_credentials"`

	// ExposeHeaders defines a whitelist headers that clients are allowed to
	// access.
	// Optional. Default value []string{}.
	ExposeHeaders []string `yaml:"expose_headers"`

	// MaxAge indicates how long (in seconds) the results of a preflight request
	// can be cached.
	// Optional. Default value 0.
	MaxAge int `yaml:"max_age"`
}

Options defines the config for CORS middleware.

func GetDefaultOptions

func GetDefaultOptions() Options

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL