cors

package
v1.11.21 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: Apache-2.0 Imports: 5 Imported by: 3 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cors does cors stuff

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	Skipper:  middleware.DefaultSkipper,
	Prefixes: nil,
}

DefaultConfig creates a default config

View Source
var DefaultSchemas = []string{
	"http://",
	"https://",
}

DefaultSchemas is a list of default allowed schemas for CORS origins

Functions

func MustNew added in v0.8.3

func MustNew(allowedOrigins []string) echo.MiddlewareFunc

MustNew creates a new middleware function with the default config or panics if it fails

func NewWithConfig

func NewWithConfig(config Config) (echo.MiddlewareFunc, error)

NewWithConfig creates a new middleware function with the provided config

func Validate

func Validate(origins []string) error

Validate checks a list of origins to see if they comply with the allowed origins

Types

type Config

type Config struct {
	// Enable or disable the CORS middleware
	Enabled bool               `json:"enabled" koanf:"enabled" default:"true"`
	Skipper middleware.Skipper `json:"-" koanf:"-"`
	// Prefixes is a map of prefixes to allowed origins
	Prefixes map[string][]string `json:"prefixes" koanf:"prefixes"`
	// AllowOrigins is a list of allowed origins
	AllowOrigins []string `json:"alloworigins" koanf:"alloworigins" domain:"inherit" domainPrefix:"https://console,https://docs,https://www"`
	// CookieInsecure sets the cookie to be insecure
	CookieInsecure bool `json:"cookieinsecure" koanf:"cookieinsecure"`
}

Config holds the cors configuration settings

type ValidationError

type ValidationError struct {
	Validation string
	Allowed    string
}

ValidationError is returned when the origins do not pass validation

func (*ValidationError) Error

func (e *ValidationError) Error() string

Error returns the ValidationError in string format

Jump to

Keyboard shortcuts

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