middleware

package
v0.0.0-...-04efeb6 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2025 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdminAuth

func AdminAuth() func(c *gin.Context)

func Auth

func Auth() gin.HandlerFunc

Auth 中间件:基于 Session 和 JWT 的混合认证示例 此处为示例,如果同时支持 session 和 JWT,可先检查 Session,再检查 JWT

func CORS

func CORS() gin.HandlerFunc

CORS 中间件:允许所有来源及自定义配置(此处允许所有头部、方法和跨域 cookie)

func Cache

func Cache() gin.HandlerFunc

Cache 中间件:根据请求 URI 设置 Cache-Control 头

func CriticalRateLimit

func CriticalRateLimit() func(c *gin.Context)

func DownloadRateLimit

func DownloadRateLimit() func(c *gin.Context)

func GenerateToken

func GenerateToken(userID uint, username string) (string, error)

GenerateToken 生成JWT token

func GinLoggerMiddleware

func GinLoggerMiddleware() gin.HandlerFunc

GinLoggerMiddleware 是一个 Gin 中间件,记录请求日志并调用全局 Logger 输出日志信息

func GlobalAPIRateLimit

func GlobalAPIRateLimit() func(c *gin.Context)

func GlobalWebRateLimit

func GlobalWebRateLimit() func(c *gin.Context)

func GzipDecodeMiddleware

func GzipDecodeMiddleware() gin.HandlerFunc

GzipDecodeMiddleware 解码请求体中 gzip 压缩数据,失败时返回 400

func JWTAuth

func JWTAuth() gin.HandlerFunc

JWTAuth Gin中间件函数

func Language

func Language() gin.HandlerFunc

Language 中间件:根据 Accept-Language 设置语言环境,默认 en 或 zh-CN

func RelayPanicRecover

func RelayPanicRecover() gin.HandlerFunc

RelayPanicRecover 中间件:捕获 panic,记录详细日志并返回 500 错误

func RequestId

func RequestId() gin.HandlerFunc

RequestId 中间件:生成请求 ID,存入 Context 与响应头,方便日志追踪

func RootAuth

func RootAuth() func(c *gin.Context)

func TurnstileCheck

func TurnstileCheck() gin.HandlerFunc

func UploadRateLimit

func UploadRateLimit() func(c *gin.Context)

func UserAuth

func UserAuth() func(c *gin.Context)

Types

type Claims

type Claims struct {
	UserID   uint   `json:"userid"`
	Username string `json:"username"`
	jwt.StandardClaims
}

func GetUserFromContext

func GetUserFromContext(c *gin.Context) (*Claims, bool)

GetUserFromContext 从上下文中获取用户信息

Jump to

Keyboard shortcuts

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