From 6e595d783b47c0e968bf8ce9a6564299062f18e1 Mon Sep 17 00:00:00 2001 From: snwolyg <569616226@qq.com> Date: Mon, 27 Dec 2021 13:57:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E9=99=A4=20jwt=20=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jwt.go | 10 +++++----- jwt_test.go | 14 ++++++-------- multi.go | 7 +++---- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/jwt.go b/jwt.go index eebc696..cb4b671 100644 --- a/jwt.go +++ b/jwt.go @@ -38,7 +38,7 @@ func (ra *JwtAuth) GenerateToken(claims *MultiClaims) (string, int64, error) { // GetTokenByClaims 获取用户信息 func (ra *JwtAuth) GetTokenByClaims(cla *MultiClaims) (string, error) { - return "", ErrJwtNotSuportThisFunc + return "", nil } // GetMultiClaims 获取用户信息 @@ -64,22 +64,22 @@ func (ra *JwtAuth) GetMultiClaims(tokenString string) (*MultiClaims, error) { // SetUserTokenMaxCount 最大登录限制 func (ra *JwtAuth) SetUserTokenMaxCount(tokenMaxCount int64) error { - return ErrJwtNotSuportThisFunc + return nil } //UpdateUserTokenCacheExpire 更新过期时间 func (ra *JwtAuth) UpdateUserTokenCacheExpire(token string) error { - return ErrJwtNotSuportThisFunc + return nil } // DelUserTokenCache 删除token缓存 func (ra *JwtAuth) DelUserTokenCache(token string) error { - return ErrJwtNotSuportThisFunc + return nil } // CleanUserTokenCache 清空token缓存 func (ra *JwtAuth) CleanUserTokenCache(authorityType int, userId string) error { - return ErrJwtNotSuportThisFunc + return nil } // IsAdmin diff --git a/jwt_test.go b/jwt_test.go index 7338f88..a95ceaf 100644 --- a/jwt_test.go +++ b/jwt_test.go @@ -1,7 +1,6 @@ package multi import ( - "errors" "fmt" "testing" "time" @@ -82,8 +81,8 @@ func TestJwtDelUserTokenCache(t *testing.T) { t.Error("generate token is empty") } err := jwtAuth.DelUserTokenCache(token) - if !errors.Is(err, ErrJwtNotSuportThisFunc) { - t.Errorf("get token by claims token want %v but get %v", ErrJwtNotSuportThisFunc, err) + if err != nil { + t.Errorf("get token by claims token want %v but get %v", nil, err) } }) @@ -92,8 +91,8 @@ func TestJwtDelUserTokenCache(t *testing.T) { func TestJwtSetUserTokenMaxCount(t *testing.T) { t.Run("test redis set user token max count", func(t *testing.T) { err := jwtAuth.SetUserTokenMaxCount(3) - if !errors.Is(err, ErrJwtNotSuportThisFunc) { - t.Errorf("get token by claims token want %v but get %v", ErrJwtNotSuportThisFunc, err) + if err != nil { + t.Errorf("get token by claims token want %v but get %v", nil, err) } }) } @@ -132,9 +131,8 @@ func TestJwtGetMultiClaims(t *testing.T) { func TestJwtGetTokenByClaims(t *testing.T) { t.Run("test get token by claims", func(t *testing.T) { _, err := jwtAuth.GetTokenByClaims(jwtClaims) - - if !errors.Is(err, ErrJwtNotSuportThisFunc) { - t.Errorf("get token by claims token want %v but get %v", ErrJwtNotSuportThisFunc, err) + if err != nil { + t.Errorf("get token by claims token want %v but get %v", nil, err) } }) diff --git a/multi.go b/multi.go index 90726c2..5673c5b 100644 --- a/multi.go +++ b/multi.go @@ -23,10 +23,9 @@ var ( // 错误类型 var ( - ErrTokenInvalid = errors.New("TOKEN不可用") - ErrEmptyToken = errors.New("TOKEN为空") - ErrOverMaxTokenCount = errors.New("已达到同时登录设备上限") - ErrJwtNotSuportThisFunc = errors.New("JWT验证不支持次方法") + ErrTokenInvalid = errors.New("TOKEN不可用") + ErrEmptyToken = errors.New("TOKEN为空") + ErrOverMaxTokenCount = errors.New("已达到同时登录设备上限") ) // 授权角色类型