token.go 728 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package token
  2. import (
  3. "net/url"
  4. "time"
  5. "github.com/dgrijalva/jwt-go"
  6. )
  7. var _ Token = (*token)(nil)
  8. type Token interface {
  9. // i 为了避免被其他包实现
  10. i()
  11. // JwtSign JWT 签名方式
  12. JwtSign(userId uint64, userName string, expireDuration time.Duration) (tokenString string, err error)
  13. JwtParse(tokenString string) (*claims, 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. }
  20. type claims struct {
  21. UserID uint64 `json:"uid"`
  22. Platform string `json:"pfm"`
  23. jwt.StandardClaims
  24. }
  25. func New(secret string) Token {
  26. return &token{
  27. secret: secret,
  28. }
  29. }
  30. func (t *token) i() {}