From ddd2413386bec2b046a4ee392f1218357f2da2a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Thu, 10 Aug 2023 17:32:31 +0800 Subject: [PATCH] remove jwt --- init.go | 3 --- jwt.go | 66 --------------------------------------------------------- 2 files changed, 69 deletions(-) delete mode 100644 jwt.go diff --git a/init.go b/init.go index f59eee1..69720ea 100644 --- a/init.go +++ b/init.go @@ -24,8 +24,6 @@ var ( Project *project // Array 数组操作 Array *array - // JWT ... - JWT *ownJwt // Console 控制台输出数据 Console *console // PinYin 汉字转拼音 @@ -41,7 +39,6 @@ func init() { Calculate = &calculate{} Project = &project{} Array = &array{} - JWT = &ownJwt{} Console = &console{} PinYin = &pinYin{} } diff --git a/jwt.go b/jwt.go deleted file mode 100644 index 50d9664..0000000 --- a/jwt.go +++ /dev/null @@ -1,66 +0,0 @@ -// Package util ... -// -// Description : go-jwt具体实现 -// -// Author : go_developer@163.com<白茶清欢> -// -// Date : 2023-02-11 20:09 -package util - -import ( - "errors" - - "github.com/dgrijalva/jwt-go/v4" -) - -type ownJwt struct { -} - -type MyClaims struct { - jwt.StandardClaims -} - -// Generate 生成 token -// -// Author : go_developer@163.com<白茶清欢> -// -// Date : 20:13 2023/2/11 -func (j *ownJwt) Generate(signMethod jwt.SigningMethod, secret string, claims jwt.Claims) (string, error) { - if nil == signMethod { - signMethod = jwt.SigningMethodHS256 - } - var ( - token *jwt.Token - ) - - if nil == claims { - token = jwt.New(signMethod) - } else { - token = jwt.NewWithClaims(signMethod, claims) - } - return token.SignedString([]byte(secret)) -} - -// Validate 验证token -// -// Author : go_developer@163.com<白茶清欢> -// -// Date : 20:13 2023/2/11 -func (j *ownJwt) Validate(inputToken string, secret string, claims jwt.Claims) (jwt.Claims, error) { - - var ( - token *jwt.Token - err error - ) - - if token, err = jwt.ParseWithClaims(inputToken, claims, func(tokenInfo *jwt.Token) (interface{}, error) { - return []byte(secret), nil - }); nil != err { - return nil, errors.New("token parse fail : " + err.Error()) - } - if !token.Valid { - return nil, errors.New("token is valid : " + err.Error()) - } - - return token.Claims, nil -}