Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsAPIKeyRequest ¶
func OriginInAllowlist ¶
func OriginMatchesHost ¶
func SplitAllowlist ¶
Types ¶
type CorsController ¶
type CorsController struct {
// contains filtered or unexported fields
}
CorsController 保存 CORS 中间件的可热更新状态。
相比过去把 config.Subscribe 直接埋在中间件闭包里,这里把「当前配置」抽成显式对象:
- 需要热更新的状态集中在 controller 上,由外部(启动生命周期里的 reload 管理器) 统一调用 Update,避免订阅逻辑散落在中间件内部。
- Middleware() 只负责读取当前状态并执行 CORS 校验,不再自行订阅配置事件。
func NewCorsController ¶
func NewCorsController(enabled bool, allowedOrigins string) *CorsController
NewCorsController 使用初始配置构造一个 CORS 控制器。
func (*CorsController) Middleware ¶
func (ctrl *CorsController) Middleware() gin.HandlerFunc
Middleware 返回读取当前控制器状态的 gin 中间件。
func (*CorsController) Update ¶
func (ctrl *CorsController) Update(event config.ConfigEvent) bool
Update 根据配置事件刷新 CORS 相关状态。返回是否有字段发生变化。
Click to show internal directories.
Click to hide internal directories.