153 lines
3.4 KiB
Go
153 lines
3.4 KiB
Go
package common
|
||
|
||
import "time"
|
||
|
||
// redisTokenConst Redis Token 相关常量
|
||
type redisTokenConst struct {
|
||
Prefix string
|
||
Expire time.Duration
|
||
}
|
||
|
||
// redisUserScoreConst Redis 用户成绩相关常量
|
||
type redisUserScoreConst struct {
|
||
Prefix string
|
||
Expire time.Duration
|
||
}
|
||
|
||
// redisUserProfileConst Redis 用户信息相关常量
|
||
type redisUserProfileConst struct {
|
||
Prefix string
|
||
Expire time.Duration
|
||
}
|
||
|
||
// redisConst Redis 常量集合
|
||
type redisConst struct {
|
||
Prefix string
|
||
Token redisTokenConst
|
||
UserScore redisUserScoreConst
|
||
UserProfile redisUserProfileConst
|
||
}
|
||
|
||
// RedisConst Redis 相关常量,使用方式:RedisConst.Token.Prefix
|
||
var RedisConst = redisConst{
|
||
Prefix: "wz:",
|
||
// 登录Token相关常量
|
||
Token: redisTokenConst{
|
||
Prefix: "wz:login:token:",
|
||
Expire: 24 * time.Hour,
|
||
},
|
||
// 用户成绩相关常量
|
||
UserScore: redisUserScoreConst{
|
||
Prefix: "wz:user:score:",
|
||
Expire: 8 * time.Hour,
|
||
},
|
||
// 用户信息相关常量
|
||
UserProfile: redisUserProfileConst{
|
||
Prefix: "wz:user:profile:",
|
||
Expire: 10 * time.Minute,
|
||
},
|
||
}
|
||
|
||
// httpConst HTTP/Context 相关常量
|
||
type httpConst struct {
|
||
// 上下文中存储用户信息的key
|
||
ContextUserKey string
|
||
// 请求头中Token的key
|
||
TokenHeader string
|
||
// 请求头中Token的前缀
|
||
HeaderTokenPrefix string
|
||
}
|
||
|
||
// HttpConst HTTP 相关常量,使用方式:HttpConst.TokenHeader
|
||
var HttpConst = httpConst{
|
||
ContextUserKey: "loginUser",
|
||
TokenHeader: "Authorization",
|
||
HeaderTokenPrefix: "Bearer ",
|
||
}
|
||
|
||
// errConst 错误信息常量
|
||
type errConst struct {
|
||
// 未设置租户Id
|
||
TenantIDMissing string
|
||
// 手机号和密码不能为空
|
||
PhonePwdMissing string
|
||
}
|
||
|
||
// ErrConst 错误信息常量,使用方式:ErrConst.TenantIDMissing
|
||
var ErrConst = errConst{
|
||
TenantIDMissing: "未设置租户Id",
|
||
PhonePwdMissing: "手机号和密码不能为空",
|
||
}
|
||
|
||
// stateConst 业务状态常量
|
||
type stateConst struct {
|
||
Active string
|
||
Inactive string
|
||
History string
|
||
}
|
||
|
||
// StateConst 业务状态常量,使用方式:StateConst.Active
|
||
var StateConst = stateConst{
|
||
Active: "1", // 使用中
|
||
Inactive: "0", // 未使用/已删除
|
||
History: "2", // 历史记录
|
||
}
|
||
|
||
// numberConst 数值常量
|
||
type numberConst struct {
|
||
N0 int
|
||
N0p75 float64
|
||
N0p5 float64
|
||
N5 int
|
||
N7p5 float64
|
||
N100 int
|
||
}
|
||
|
||
// NumberConst 数值常量,使用方式:NumberConst.N100
|
||
var NumberConst = numberConst{
|
||
N0: 0,
|
||
N0p75: 0.75,
|
||
N0p5: 0.5,
|
||
N5: 5,
|
||
N7p5: 7.5,
|
||
N100: 100,
|
||
}
|
||
|
||
// dataTypeConst 数据类型常量
|
||
type dataTypeConst struct {
|
||
Normal string
|
||
Art string
|
||
}
|
||
|
||
// DataTypeConst 数据类型常量,使用方式:DataTypeConst.Normal
|
||
var DataTypeConst = dataTypeConst{
|
||
Normal: "1", // 普通类
|
||
Art: "2", // 艺术类
|
||
}
|
||
|
||
// admissionConst 录取方式常量
|
||
type admissionConst struct {
|
||
CulturalControlLineGuo string
|
||
SpecialControlLineGuo string
|
||
CulturalControlLineGuoMain string
|
||
W1Z1 string
|
||
W1JiaZ1 string
|
||
}
|
||
|
||
// AdmissionConst 录取方式常量,使用方式:AdmissionConst.CulturalControlLineGuo
|
||
var AdmissionConst = admissionConst{
|
||
CulturalControlLineGuo: "文线专排",
|
||
SpecialControlLineGuo: "专过文排",
|
||
CulturalControlLineGuoMain: "文过专排主科",
|
||
W1Z1: "文*1+专*1",
|
||
W1JiaZ1: "文+专",
|
||
}
|
||
|
||
// NowYear 当前年份
|
||
const NowYear = "2026"
|
||
|
||
var (
|
||
OldYearList = []string{"2025", "2024"}
|
||
ShowOldYearList = []string{"2025", "2024", "2023"}
|
||
)
|