cors

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Default

func Default() gin.HandlerFunc

Default 返回使用默认配置的 CORS 中间件

func New

func New(config Config) gin.HandlerFunc

New 创建 CORS 中间件

Types

type Config

type Config struct {
	// AllowOrigins 允许的源列表,如 ["http://localhost:3000", "https://example.com"]
	// 使用 "*" 表示允许所有源(不推荐用于生产环境)
	AllowOrigins []string

	// AllowMethods 允许的 HTTP 方法
	AllowMethods []string

	// AllowHeaders 允许的请求头
	AllowHeaders []string

	// ExposeHeaders 暴露给客户端的响应头
	ExposeHeaders []string

	// AllowCredentials 是否允许携带凭证(Cookie、HTTP 认证等)
	AllowCredentials bool

	// MaxAge 预检请求的缓存时间(秒)
	MaxAge int
}

Config CORS 配置

func DefaultConfig

func DefaultConfig() Config

DefaultConfig 返回默认的 CORS 配置

Jump to

Keyboard shortcuts

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