token.go 684 B

123456789101112131415161718192021222324252627282930313233343536
  1. package token
  2. import (
  3. "net/url"
  4. "time"
  5. "github.com/golang-jwt/jwt/v4"
  6. )
  7. var _ Token = (*token)(nil)
  8. type Token interface {
  9. // i 为了避免被其他包实现
  10. i()
  11. // JwtSign JWT 签名方式
  12. JwtSign(userId, subject string, expireDuration time.Duration) (tokenString string, err error)
  13. JwtParse(tokenString string) (*jwt.RegisteredClaims, error)
  14. // UrlSign URL 签名方式,不支持解密
  15. UrlSign(path string, method string, params url.Values) (tokenString string, err error)
  16. }
  17. type token struct {
  18. secret string
  19. domain []string
  20. }
  21. func New(secret string, domain ...string) Token {
  22. return &token{
  23. secret: secret,
  24. domain: domain,
  25. }
  26. }
  27. func (t *token) i() {}