This commit is contained in:
2026-07-12 23:19:42 +08:00
parent 94f6ecf901
commit 2dcafae465
14 changed files with 2303 additions and 0 deletions

View File

@@ -43,6 +43,16 @@ func ParseToken(tokenString, secret string) (*JWTClaims, error) {
}
if claims, ok := token.Claims.(*JWTClaims); ok && token.Valid {
jsonBytes, err := json.MarshalIndent(claims, "", " ") // MarshalIndent 用于格式化输出,更易读
if err != nil {
// 记录序列化错误,但不一定中断业务逻辑,视需求而定
log.Printf("Failed to marshal claims to JSON: %v", err)
} else {
// 2. 在控制台输出 JSON 字符串
fmt.Println("=== Decoded JWT Claims ===")
fmt.Println(string(jsonBytes))
fmt.Println("==========================")
}
return claims, nil
}