middleware

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccessLog

func AccessLog(logger logContract.Logger, config AccessLogConfig) gin.HandlerFunc

AccessLog 访问日志中间件 记录HTTP请求的访问日志,支持跳过指定路径

func HttpsRedirect

func HttpsRedirect() gin.HandlerFunc

HttpsRedirect 重定向 HTTP 请求到 HTTPS

func RateLimiter

func RateLimiter(period time.Duration, limit int64) gin.HandlerFunc

func Recovery

func Recovery(logger logContract.Logger) gin.HandlerFunc

func RequestID

func RequestID() gin.HandlerFunc

RequestID 请求ID中间件 为每个请求生成唯一的请求ID,用于日志追踪和调试

func Security

func Security(config SecurityConfig) gin.HandlerFunc

Security 安全头中间件 添加各种安全相关的HTTP头,提高应用安全性

Types

type AccessLogConfig

type AccessLogConfig struct {
	Enabled   bool     `yaml:"enabled"`
	Format    string   `yaml:"format"`
	SkipPaths []string `yaml:"skip-paths"`
}

AccessLogConfig 访问日志配置

type SecurityConfig

type SecurityConfig struct {
	ContentTypeNoSniff bool `yaml:"content-type-nosniff"`
	XssProtection      bool `yaml:"xss-protection"`
	FrameDeny          bool `yaml:"frame-deny"`
	Hsts               bool `yaml:"hsts"`
	HstsMaxAge         int  `yaml:"hsts-max-age"`
}

SecurityConfig 安全配置

Jump to

Keyboard shortcuts

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