cors

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware(config *Config) func(http.Handler) http.Handler

Middleware is the CORS middleware function that takes a Config struct and returns the middleware.

func ValidateOriginFromList

func ValidateOriginFromList(allowedOrigins []string) func(string) bool

ValidateOriginFromList returns a function that validates an origin against the provided list of allowed origins.

Types

type Config

type Config struct {
	AllowCredentials bool              // Flag to allow sending of credentials (cookies, etc.).
	AllowedMethods   []string          // List of allowed HTTP methods.
	AllowedHeaders   []string          // List of allowed HTTP request headers.
	ExposedHeaders   []string          // List of exposed response headers.
	MaxAge           int               // Maximum age (in seconds) of the CORS preflight cache.
	ValidateHeader   func(string) bool // Custom function to validate the request headers.
	ValidateOrigin   func(string) bool // Custom function to validate the origin.
}

Config is a struct that holds configuration options for the CORS middleware.

func NewConfig

func NewConfig() *Config

NewConfig creates a new Config struct with default values.

Jump to

Keyboard shortcuts

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