cors

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Enabled          bool     `json:"enabled,omitempty" yaml:"enabled" ini:"enabled"`                               // 是否启用CORS
	AllowOrigins     []string `json:"allow_origins,omitempty" yaml:"allow_origins" ini:"allow_origins"`             // 允许的源
	AllowMethods     []string `json:"allow_methods,omitempty" yaml:"allow_methods" ini:"allow_methods"`             // 允许的HTTP方法
	AllowHeaders     []string `json:"allow_headers,omitempty" yaml:"allow_headers" ini:"allow_headers"`             // 允许的请求头
	AllowCredentials bool     `json:"allow_credentials,omitempty" yaml:"allow_credentials" ini:"allow_credentials"` // 是否允许发送 Cookie
	ExposeHeaders    []string `json:"expose_headers,omitempty" yaml:"expose_headers" ini:"expose_headers"`          // 暴露给前端的响应头
	MaxAge           int      `json:"max_age,omitempty" yaml:"max_age" ini:"max_age"`                               // 预检请求缓存时间(秒)
	Strict           bool     `json:"strict,omitempty" yaml:"strict" ini:"strict"`                                  // 严格模式 严格模式下,不允许的Origin阻值后不继续后续流程
}

Config CORS配置结构体

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig 默认配置

func StrictConfig

func StrictConfig() Config

StrictConfig 返回严格的CORS配置

func (*Config) Apply

func (c *Config) Apply(w http.ResponseWriter, origin string) bool

func (*Config) Clone

func (c *Config) Clone() *Config

Clone 创建配置的深拷贝

func (*Config) Disable

func (c *Config) Disable() *Config

Disable 禁用CORS

func (*Config) Enable

func (c *Config) Enable() *Config

Enable 启用CORS

func (*Config) GobDecode

func (c *Config) GobDecode(data []byte) error

func (Config) GobEncode

func (c Config) GobEncode() ([]byte, error)

func (Config) GormDBDataType

func (Config) GormDBDataType(db *gorm.DB, field *schema.Field) string

func (Config) GormDataType

func (c Config) GormDataType() string

func (Config) GormValue

func (c Config) GormValue(_ context.Context, db *gorm.DB) clause.Expr

func (*Config) HandlePreflight

func (c *Config) HandlePreflight(w http.ResponseWriter, origin string)

HandlePreflight 预检请求处理

func (*Config) Scan

func (c *Config) Scan(val any) (err error)

func (Config) Value

func (c Config) Value() (driver.Value, error)

func (*Config) WithCredentials

func (c *Config) WithCredentials(allow bool) *Config

WithCredentials 设置是否允许凭据

func (*Config) WithExposeHeaders

func (c *Config) WithExposeHeaders(headers ...string) *Config

WithExposeHeaders 设置暴露的响应头

func (*Config) WithHeaders

func (c *Config) WithHeaders(headers ...string) *Config

WithHeaders 设置允许的请求头

func (*Config) WithMaxAge

func (c *Config) WithMaxAge(seconds int) *Config

WithMaxAge 设置预检请求缓存时间

func (*Config) WithMethods

func (c *Config) WithMethods(methods ...string) *Config

WithMethods 设置允许的方法

func (*Config) WithOrigins

func (c *Config) WithOrigins(origins ...string) *Config

WithOrigins 设置允许的源

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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