goacors

package module
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2019 License: MIT Imports: 7 Imported by: 0

README

Build Status Coverage Status GoDoc

goacors

a cors-header middleware for goa(https://github.com/goadesign/goa). This is a fork of https://github.com/istyle-inc/goacors

how to use

  1. go get github.com/shogo82148/goacors
  2. write your main.go generated automatically from goagen.
service.Use(goacors.WithConfig(service, &goacors.DefaultGoaCORSConfig))

or

service.Use(goacors.WithConfig(service, &goacors.GoaCORSConfig{
	AllowOrigins: []string{"http://example.com"},
	AllowMethods: []string{http.MethodGet},
}))

Documentation

Index

Constants

View Source
const (
	// HeaderVary "Vary"
	HeaderVary = "Vary"
	// HeaderOrigin "Origin"
	HeaderOrigin = "Origin"
	// HeaderAccessControlRequestMethod "Access-Control-Request-Method"
	HeaderAccessControlRequestMethod = "Access-Control-Request-Method"
	// HeaderAccessControlRequestHeaders "Access-Control-Request-Headers"
	HeaderAccessControlRequestHeaders = "Access-Control-Request-Headers"
	// HeaderAccessControlAllowOrigin Access-Control-Allow-Origin"
	HeaderAccessControlAllowOrigin = "Access-Control-Allow-Origin"
	// HeaderAccessControlAllowMethods "Access-Control-Allow-Methods"
	HeaderAccessControlAllowMethods = "Access-Control-Allow-Methods"
	// HeaderAccessControlAllowHeaders "Access-Control-Allow-Headers"
	HeaderAccessControlAllowHeaders = "Access-Control-Allow-Headers"
	// HeaderAccessControlAllowCredentials "Access-Control-Allow-Credentials"
	HeaderAccessControlAllowCredentials = "Access-Control-Allow-Credentials"
	// HeaderAccessControlExposeHeaders "Access-Control-Expose-Headers"
	HeaderAccessControlExposeHeaders = "Access-Control-Expose-Headers"
	// HeaderAccessControlMaxAge "Access-Control-Max-Age"
	HeaderAccessControlMaxAge = "Access-Control-Max-Age"
	// HeaderContentType "Content-Type"
	HeaderContentType = "Content-Type"
)

Variables

This section is empty.

Functions

func New

func New(service *goa.Service, conf *Config) goa.Middleware

New creates middleware with configure for this

Types

type Config

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

	// AllowOrigin defines a list of origins that may access the resource.
	// Default value is an empty list, any origin can not access.
	AllowOrigins []string

	// AllowMethods defines a list methods allowed when accessing the resource.
	// This is used in response to a preflight request.
	// Default value is an empty list, any method is not allowed.
	AllowMethods []string

	// AllowHeaders defines a list of request headers that can be used when
	// making the actual request. This in response to a preflight request.
	AllowHeaders []string

	// 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.
	// Default value is false.
	AllowCredentials bool

	// ExposeHeaders defines a whitelist headers that clients are allowed to
	// access.
	// Default value is an empty list.
	ExposeHeaders []string

	// MaxAge indicates how long (in seconds) the results of a preflight request
	// can be cached.
	// The default value is 0, the preflight request can not be cached.
	MaxAge int
}

Config is a config for the CORS middleware.

type Skipper

type Skipper func(c context.Context, rw http.ResponseWriter, req *http.Request) bool

Skipper defines a function to skip middleware. Returning true skips processing the middleware.

Jump to

Keyboard shortcuts

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