cors

package
v0.25.3 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cors

type Cors struct {
	Enabled             bool     `mapstructure:"enabled" yaml:"enabled" json:"enabled"`                                                       // 是否启用CORS
	AllowedOrigins      []string `mapstructure:"allowed-origins" yaml:"allowed-origins" json:"allowedOrigins"       validate:"dive,required"` // 允许的来源
	AllowedMethods      []string `mapstructure:"allowed-methods" yaml:"allowed-methods" json:"allowedMethods"       validate:"dive,required"` // 允许的方法
	AllowedHeaders      []string `mapstructure:"allowed-headers" yaml:"allowed-headers" json:"allowedHeaders"       validate:"dive,required"` // 允许的头部
	MaxAge              string   `mapstructure:"max-age" yaml:"max-age" json:"maxAge"               validate:"required"`                      // 最大缓存时间
	AllowedAllOrigins   bool     `mapstructure:"allowed-all-origins" yaml:"allowed-all-origins" json:"allowedAllOrigins"`                     // 是否允许所有来源
	AllowedAllMethods   bool     `mapstructure:"allowed-all-methods" yaml:"allowed-all-methods" json:"allowedAllMethods"`                     // 是否允许所有方法
	ExposedHeaders      []string `mapstructure:"exposed-headers" yaml:"exposed-headers" json:"exposedHeaders"`                                // 暴露的头部
	AllowCredentials    bool     `mapstructure:"allow-credentials" yaml:"allow-credentials" json:"allowCredentials"`                          // 允许凭证
	OptionsResponseCode int      `mapstructure:"options-response-code" yaml:"options-response-code" json:"optionsResponseCode"`               // Options响应Code
	ModuleName          string   `mapstructure:"module-name" yaml:"module-name" json:"moduleName"`                                            // 模块名称
}

Cors 跨域资源共享配置

func Default

func Default() *Cors

Default 返回默认Cors配置的指针,支持链式调用

func DefaultCors

func DefaultCors() Cors

DefaultCors 返回默认Cors配置

func NewCors

func NewCors(opt *Cors) *Cors

NewCors 创建一个新的 Cors 实例

func (*Cors) Clone

func (c *Cors) Clone() internal.Configurable

Clone 返回 Cors 配置的副本

func (*Cors) Get

func (c *Cors) Get() interface{}

Get 返回 Cors 配置的所有字段

func (*Cors) Set

func (c *Cors) Set(data interface{})

Set 更新 Cors 配置的字段

func (*Cors) Validate

func (c *Cors) Validate() error

Validate 检查 Cors 配置的有效性

func (*Cors) WithAllowCredentials

func (c *Cors) WithAllowCredentials(allowCredentials bool) *Cors

WithAllowCredentials 设置是否允许凭证

func (*Cors) WithAllowedAllMethods

func (c *Cors) WithAllowedAllMethods(allowedAllMethods bool) *Cors

WithAllowedAllMethods 设置是否允许所有方法

func (*Cors) WithAllowedAllOrigins

func (c *Cors) WithAllowedAllOrigins(allowedAllOrigins bool) *Cors

WithAllowedAllOrigins 设置是否允许所有来源

func (*Cors) WithAllowedHeaders

func (c *Cors) WithAllowedHeaders(allowedHeaders []string) *Cors

WithAllowedHeaders 设置允许的头部

func (*Cors) WithAllowedMethods

func (c *Cors) WithAllowedMethods(allowedMethods []string) *Cors

WithAllowedMethods 设置允许的方法

func (*Cors) WithAllowedOrigins

func (c *Cors) WithAllowedOrigins(allowedOrigins []string) *Cors

WithAllowedOrigins 设置允许的来源

func (*Cors) WithEnabled

func (c *Cors) WithEnabled(enabled bool) *Cors

WithEnabled 设置是否启用CORS

func (*Cors) WithExposedHeaders

func (c *Cors) WithExposedHeaders(exposedHeaders []string) *Cors

WithExposedHeaders 设置暴露的头部

func (*Cors) WithMaxAge

func (c *Cors) WithMaxAge(maxAge string) *Cors

WithMaxAge 设置最大缓存时间

func (*Cors) WithModuleName

func (c *Cors) WithModuleName(moduleName string) *Cors

WithModuleName 设置模块名称

func (*Cors) WithOptionsResponseCode

func (c *Cors) WithOptionsResponseCode(optionsResponseCode int) *Cors

WithOptionsResponseCode 设置Options响应码

Jump to

Keyboard shortcuts

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