Files
zogo/jwtx/README.md
T

20 lines
699 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# jwtx
轻量 HS256 JWT(标准库实现,零外部依赖)。密钥显式传参,不落全局状态。
## 用法
```go
import "git.zeroonesoft.cn/golib/zogo/jwtx"
token, err := jwtx.Sign(secret, jwtx.Claims{UserID: 42, Role: "admin", Exp: time.Now().Add(time.Hour).Unix()})
claims, err := jwtx.Parse(secret, token) // 签名错→ErrInvalidToken,过期→ErrExpired
```
## 说明
- 标准三段式 `header.payload.signature`(HS256),`Claims{UserID, Role, Exp}` 为登录令牌
通用三字段;需要更多业务字段时建议换成 `github.com/golang-jwt/jwt`,本包定位是
零依赖场景的最小实现。
- **密钥必须从配置/环境注入**,不要硬编码。