cors

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CorsPropertiesPrefix = "security.cors"
)

Variables

View Source
var Module = &bootstrap.Module{
	Name:       "CORS",
	Precedence: web.MinWebPrecedence + 1,
	PriorityOptions: []fx.Option{
		fx.Provide(BindCorsProperties),
		web.FxCustomizerProviders(newCustomizer),
	},
}

Functions

func New

func New(options Options) gin.HandlerFunc

New creates a new CORS Gin middleware with the provided options.

Types

type CorsProperties

type CorsProperties struct {
	Enabled bool `json:"enabled"`
	// Comma-separated list of origins to allow. '*' allows all origins. Default to '*'
	AllowedOriginsStr string `json:"allowed-origins"`
	// Comma-separated list of methods to allow. '*' allows all methods. Default to '*'
	AllowedMethodsStr string `json:"allowed-methods"`
	// Comma-separated list of headers to allow in a request. '*' allows all headers. Default to '*'
	AllowedHeadersStr string `json:"allowed-headers"`
	// Comma-separated list of headers to include in a response.
	ExposedHeadersStr string `json:"exposed-headers"`
	// Whether credentials are supported. When not set, credentials are not supported.
	AllowCredentials bool `json:"allow-credentials"`
	// How long the response from a pre-flight request can be cached by clients.
	// If a duration suffix is not specified, seconds will be used.
	MaxAge utils.Duration `json:"max-age"`
}

func BindCorsProperties

func BindCorsProperties(ctx *bootstrap.ApplicationContext) CorsProperties

BindCorsProperties create and bind a ServerProperties using default prefix

func NewCorsProperties

func NewCorsProperties() *CorsProperties

NewCorsProperties create a ServerProperties with default values

func (CorsProperties) AllowedHeaders

func (p CorsProperties) AllowedHeaders() []string

func (CorsProperties) AllowedMethods

func (p CorsProperties) AllowedMethods() []string

func (CorsProperties) AllowedOrigins

func (p CorsProperties) AllowedOrigins() []string

func (CorsProperties) ExposedHeaders

func (p CorsProperties) ExposedHeaders() []string

type Customizer

type Customizer struct {
	// contains filtered or unexported fields
}

Customizer implements web.Customizer

func (*Customizer) Customize

func (c *Customizer) Customize(_ context.Context, r *web.Registrar) (err error)

type Options

type Options = cors.Options

Options is a configuration container to setup the CORS middleware.

Jump to

Keyboard shortcuts

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