1234567891011121314151617181920212223242526272829303132333435363738394041 |
- package token
- import (
- "net/url"
- "time"
- "github.com/golang-jwt/jwt/v4"
- )
- var _ Token = (*token)(nil)
- type Token interface {
- // i 为了避免被其他包实现
- i()
- // JwtSign JWT 签名方式
- JwtSign(userId uint64, userName string, expireDuration time.Duration) (tokenString string, err error)
- JwtParse(tokenString string) (*claims, error)
- // UrlSign URL 签名方式,不支持解密
- UrlSign(path string, method string, params url.Values) (tokenString string, err error)
- }
- type token struct {
- secret string
- domain string
- }
- type claims struct {
- UserID uint64 `json:"uid"`
- jwt.RegisteredClaims
- }
- func New(secret, domain string) Token {
- return &token{
- secret: secret,
- domain: domain,
- }
- }
- func (t *token) i() {}
|