Documentation
¶
Index ¶
- type Config
- func (c *Config) Apply(w http.ResponseWriter, origin string) bool
- func (c *Config) Clone() *Config
- func (c *Config) Disable() *Config
- func (c *Config) Enable() *Config
- func (c *Config) GobDecode(data []byte) error
- func (c Config) GobEncode() ([]byte, error)
- func (Config) GormDBDataType(db *gorm.DB, field *schema.Field) string
- func (c Config) GormDataType() string
- func (c Config) GormValue(_ context.Context, db *gorm.DB) clause.Expr
- func (c *Config) HandlePreflight(w http.ResponseWriter, origin string)
- func (c *Config) Scan(val any) (err error)
- func (c Config) Value() (driver.Value, error)
- func (c *Config) WithCredentials(allow bool) *Config
- func (c *Config) WithExposeHeaders(headers ...string) *Config
- func (c *Config) WithHeaders(headers ...string) *Config
- func (c *Config) WithMaxAge(seconds int) *Config
- func (c *Config) WithMethods(methods ...string) *Config
- func (c *Config) WithOrigins(origins ...string) *Config
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 (Config) GormDBDataType ¶
func (Config) GormDataType ¶
func (*Config) HandlePreflight ¶
func (c *Config) HandlePreflight(w http.ResponseWriter, origin string)
HandlePreflight 预检请求处理
func (*Config) WithCredentials ¶
WithCredentials 设置是否允许凭据
func (*Config) WithExposeHeaders ¶
WithExposeHeaders 设置暴露的响应头
func (*Config) WithHeaders ¶
WithHeaders 设置允许的请求头
func (*Config) WithMethods ¶
WithMethods 设置允许的方法
func (*Config) WithOrigins ¶
WithOrigins 设置允许的源
Click to show internal directories.
Click to hide internal directories.