初始化

This commit is contained in:
SunYF
2026-08-28 14:07:22 +08:00
parent a185247ab1
commit b34325a16f
971 changed files with 291 additions and 220360 deletions
-33
View File
@@ -1,33 +0,0 @@
package token
import (
"encoding/base64"
"fmt"
"github.com/golang-jwt/jwt/v4"
"github.com/google/uuid"
)
const RefreshTokenKeyPrefix = "token:refresh:"
func GenToken(secretKey string, iat int64, expireSeconds int64, payloads map[string]any) (string, error) {
claims := make(jwt.MapClaims)
claims["exp"] = iat + expireSeconds
claims["iat"] = iat
for k, v := range payloads {
claims[k] = v
}
token := jwt.New(jwt.SigningMethodHS256)
token.Claims = claims
return token.SignedString([]byte(secretKey))
}
func GenRefreshToken() string {
return base64.StdEncoding.EncodeToString([]byte(uuid.New().String()))
}
func GenRefreshTokenCacheKey(userId int64) string {
return fmt.Sprintf("%s%d", RefreshTokenKeyPrefix, userId)
}