middleware

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var JWTSecret = []byte("zenops-jwt-secret-key-change-in-production")

JWT 密钥,实际生产环境应该从配置文件中读取

Functions

func AuthMiddleware

func AuthMiddleware() gin.HandlerFunc

AuthMiddleware JWT 认证中间件

func GenerateToken

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

GenerateToken 生成 JWT Token

func OptionalAuthMiddleware

func OptionalAuthMiddleware() gin.HandlerFunc

OptionalAuthMiddleware 可选的认证中间件(如果有 token 则验证,没有则跳过)

Types

type Claims

type Claims struct {
	UserID   uint   `json:"user_id"`
	Username string `json:"username"`
	Roles    string `json:"roles"`
	jwt.RegisteredClaims
}

Claims JWT 声明

func ParseToken

func ParseToken(tokenString string) (*Claims, error)

ParseToken 解析 JWT Token

Jump to

Keyboard shortcuts

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