security

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAPIKeyRequest

func IsAPIKeyRequest(r *http.Request) bool

func IsAuthorizationPreflight

func IsAuthorizationPreflight(r *http.Request) bool

func OriginInAllowlist

func OriginInAllowlist(origin, rawAllowlist string) bool

func OriginMatchesHost

func OriginMatchesHost(origin, host string) bool

func SplitAllowlist

func SplitAllowlist(raw string) []string

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 相关状态。返回是否有字段发生变化。

Jump to

Keyboard shortcuts

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