✨ 重新初始化项目
This commit is contained in:
@@ -1,11 +1,8 @@
|
||||
package constant
|
||||
|
||||
const (
|
||||
RdsCaptchaPrefix = "captcha:img:" // 验证码缓存前缀
|
||||
RdsSmsCaptchaPrefix = "captcha:sms:" // 短信验证码缓存前缀
|
||||
OAuth2RedisKey = "oauth:token:" // Token缓存前缀
|
||||
OAuth2UserCacheKey = "oauth:user:" // 用户缓存前缀
|
||||
ApiAntiShakeKey = "api:antishake:" // 防抖锁
|
||||
ReportGenTaskKey = "report:gen:task" // 任务生成计划待办队列
|
||||
WeChatSessionKey = "wechat:session:" // 小程序用户SessionKey前缀
|
||||
OAuth2RedisKey = "oauth:token:" // Token缓存前缀
|
||||
OAuth2UserCacheKey = "oauth:user:" // 用户缓存前缀
|
||||
ApiAntiShakeKey = "api:antishake:" // 防抖锁
|
||||
WeChatSessionKey = "wechat:session:" // 小程序用户SessionKey前缀
|
||||
)
|
||||
|
88
common/constant/user.go
Normal file
88
common/constant/user.go
Normal file
@@ -0,0 +1,88 @@
|
||||
package constant
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// UserStatus 用户状态
|
||||
type UserStatus string
|
||||
|
||||
const (
|
||||
UserStatusActive UserStatus = "NORMAL" // 用户状态正常
|
||||
UserStatusDisabled UserStatus = "DISABLE" // 已禁用用户
|
||||
)
|
||||
|
||||
// 状态对应的描述
|
||||
var userStatusMap = map[UserStatus]string{
|
||||
UserStatusActive: "正常",
|
||||
UserStatusDisabled: "已禁用",
|
||||
}
|
||||
|
||||
// 处理为看得懂的状态
|
||||
func (s UserStatus) String() string {
|
||||
if str, ok := userStatusMap[s]; ok {
|
||||
return str
|
||||
}
|
||||
return string(s)
|
||||
}
|
||||
|
||||
// =====================================================================================================================
|
||||
|
||||
// UserSex 性别
|
||||
type UserSex int
|
||||
|
||||
const (
|
||||
UserSexNone UserSex = iota // 不知道是啥
|
||||
UserSexMale // 男
|
||||
UserSexFemale // 女
|
||||
UserSexOther // 其他性别
|
||||
)
|
||||
|
||||
// 状态对应的描述
|
||||
var userSexMap = map[UserSex]string{
|
||||
UserSexNone: "无性别",
|
||||
UserSexMale: "男",
|
||||
UserSexFemale: "女",
|
||||
UserSexOther: "其他",
|
||||
}
|
||||
|
||||
// FromString 中文取性别
|
||||
func (s UserSex) FromString(sex string) UserSex {
|
||||
result := UserSexNone
|
||||
for key, value := range userSexMap {
|
||||
if sex == value {
|
||||
result = key
|
||||
break
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// 处理为看得懂的状态
|
||||
func (s UserSex) String() string {
|
||||
if str, ok := userSexMap[s]; ok {
|
||||
return str
|
||||
}
|
||||
//return strconv.Itoa(int(s))
|
||||
return fmt.Sprintf("UserSex(%d)", int(s))
|
||||
}
|
||||
|
||||
// MarshalJSON JSON序列化的时候转换为中文
|
||||
func (s UserSex) MarshalJSON() ([]byte, error) {
|
||||
return []byte(`"` + s.String() + `"`), nil
|
||||
}
|
||||
|
||||
// =====================================================================================================================
|
||||
|
||||
// UserIdentity 用户身份
|
||||
type UserIdentity string
|
||||
|
||||
const (
|
||||
UserIdentityAdmin UserIdentity = "admin" // 管理员
|
||||
UserIdentityUser UserIdentity = "user" // 普通用户
|
||||
)
|
||||
|
||||
// String implements the Stringer interface.
|
||||
func (t UserIdentity) String() string {
|
||||
return string(t)
|
||||
}
|
Reference in New Issue
Block a user