mirror of https://github.com/go-sonic/sonic.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package cache
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
|
|
"github.com/go-sonic/sonic/consts"
|
|
"github.com/go-sonic/sonic/util/xerr"
|
|
)
|
|
|
|
func BuildTokenAccessKey(accessToken string) string {
|
|
return consts.TokenAccessCachePrefix + accessToken
|
|
}
|
|
|
|
func BuildTokenRefreshKey(refreshToken string) string {
|
|
return consts.TokenRefreshCachePrefix + refreshToken
|
|
}
|
|
|
|
func BuildAccessTokenKey(userID int32) string {
|
|
return consts.TokenAccessCachePrefix + strconv.Itoa(int(userID))
|
|
}
|
|
|
|
func BuildRefreshTokenKey(userID int32) string {
|
|
return consts.TokenRefreshCachePrefix + strconv.Itoa(int(userID))
|
|
}
|
|
|
|
func BuildCodeCacheKey(userID int32) string {
|
|
return consts.CodePrefix + strconv.Itoa(int(userID))
|
|
}
|
|
|
|
func BuildAccessPermissionKey(ctx context.Context) (string, error) {
|
|
sessionID := ctx.Value(consts.SessionID)
|
|
if sessionID == nil {
|
|
return "", xerr.NoType.New("session_id not exist").WithStatus(xerr.StatusInternalServerError)
|
|
}
|
|
sessionIDStr, ok := sessionID.(string)
|
|
if !ok || sessionIDStr == "" {
|
|
return "", xerr.NoType.New("session_id not exist").WithStatus(xerr.StatusInternalServerError)
|
|
}
|
|
return consts.AccessPermissionKeyPrefix + sessionIDStr, nil
|
|
}
|
|
|
|
func BuildCategoryPermissionKey(categoryID int32) string {
|
|
return strconv.Itoa(int(categoryID))
|
|
}
|