89 lines
1.9 KiB
Go
Executable File
89 lines
1.9 KiB
Go
Executable File
package domain
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
const (
|
|
TicketKeyPrefix = "tic/"
|
|
)
|
|
|
|
const (
|
|
ClientDataKey = "permission:clients"
|
|
)
|
|
|
|
type RedisKey string
|
|
|
|
const (
|
|
AccessTokenRedisKey RedisKey = "access_token"
|
|
RefreshTokenRedisKey RedisKey = "refresh_token"
|
|
DeviceTokenRedisKey RedisKey = "device_token"
|
|
UIDTokenRedisKey RedisKey = "uid_token"
|
|
TicketRedisKey RedisKey = "ticket"
|
|
DeviceUIDRedisKey RedisKey = "device_uid"
|
|
)
|
|
|
|
func (key RedisKey) ToString() string {
|
|
return "permission:" + string(key)
|
|
}
|
|
|
|
func (key RedisKey) With(s ...string) RedisKey {
|
|
parts := append([]string{string(key)}, s...)
|
|
return RedisKey(strings.Join(parts, ":"))
|
|
}
|
|
|
|
func GetAccessTokenRedisKey(id string) string {
|
|
return AccessTokenRedisKey.With(id).ToString()
|
|
}
|
|
|
|
func GetUIDTokenRedisKey(uid string) string {
|
|
return UIDTokenRedisKey.With(uid).ToString()
|
|
}
|
|
|
|
func GetTicketRedisKey(ticket string) string {
|
|
return TicketRedisKey.With(ticket).ToString()
|
|
}
|
|
|
|
const (
|
|
PermissionIDRedisKey RedisKey = "permission:id"
|
|
PermissionNameRedisKey RedisKey = "permission:name"
|
|
)
|
|
|
|
func GetPermissionIDRedisKey(id string) string {
|
|
return PermissionIDRedisKey.With(id).ToString()
|
|
}
|
|
|
|
func GetPermissionNameRedisKey(id string) string {
|
|
return PermissionNameRedisKey.With(id).ToString()
|
|
}
|
|
|
|
const (
|
|
RoleIDRedisKey RedisKey = "role:id"
|
|
RoleUIDRedisKey RedisKey = "role:uid"
|
|
)
|
|
|
|
func GetRoleIDRedisKey(id int64) string {
|
|
return RoleIDRedisKey.With(strconv.FormatInt(id, 10)).ToString()
|
|
}
|
|
|
|
func GetRoleUIDRedisKey(uid string) string {
|
|
return RoleUIDRedisKey.With(uid).ToString()
|
|
}
|
|
|
|
const (
|
|
RolePermissionRedisKey RedisKey = "role_permission"
|
|
)
|
|
|
|
func GetRolePermissionRedisKey(roleID int64) string {
|
|
return RolePermissionRedisKey.With(strconv.FormatInt(roleID, 10)).ToString()
|
|
}
|
|
|
|
const (
|
|
UserRoleUIDRedisKey RedisKey = "user_role:uid"
|
|
)
|
|
|
|
func GetUserRoleUIDRedisKey(uid string) string {
|
|
return UserRoleUIDRedisKey.With(uid).ToString()
|
|
}
|