You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.5 KiB
64 lines
1.5 KiB
package cache
|
|
|
|
import (
|
|
cacheApi "epur-pay/cache/api"
|
|
"epur-pay/model"
|
|
"epur-pay/pkg/config"
|
|
"epur-pay/pkg/limit"
|
|
"github.com/oschwald/geoip2-golang"
|
|
"time"
|
|
)
|
|
|
|
var Global *GlobalServerCache
|
|
|
|
/*
|
|
全局公用缓存层
|
|
*/
|
|
|
|
type GlobalServerCache struct {
|
|
ProjectInitStatus bool // 项目是否初始化完成
|
|
IpLocation *geoip2.Reader // IP库
|
|
DefaultTimeZone *time.Location // 默认时区
|
|
LimitRouter struct {
|
|
RuleKey string
|
|
Rule *limit.LimitConfRules
|
|
Api limit.LimiterIface
|
|
} // 限流器
|
|
Routers []*model.RouterMethod
|
|
Caches struct {
|
|
Config *cacheApi.Config
|
|
Language *cacheApi.Language
|
|
Version *cacheApi.Version
|
|
RolePermission *cacheApi.RolePermission // 角色菜单权限
|
|
User *cacheApi.User
|
|
BlackList *cacheApi.BlackList // 黑名单
|
|
}
|
|
}
|
|
|
|
func New() {
|
|
Global = &GlobalServerCache{}
|
|
Global.CacheDataInit()
|
|
}
|
|
|
|
func (g *GlobalServerCache) CacheDataInit() {
|
|
|
|
g.DefaultTimeZone, _ = time.LoadLocation("Asia/Shanghai")
|
|
g.LimitRouter.Rule = &limit.LimitConfRules{
|
|
Rules: make(map[string]*limit.LimitOpt),
|
|
}
|
|
g.Caches.Config = (&cacheApi.Config{}).Refresh()
|
|
g.Caches.Language = (&cacheApi.Language{}).Refresh()
|
|
g.Caches.Version = (&cacheApi.Version{}).Refresh()
|
|
g.Caches.BlackList = (&cacheApi.BlackList{}).Refresh()
|
|
g.Caches.RolePermission = (&cacheApi.RolePermission{}).Refresh()
|
|
g.Caches.User = (&cacheApi.User{}).Refresh()
|
|
|
|
if config.Cf.Common.RunMode == "release" {
|
|
NewIpLocation()
|
|
}
|
|
|
|
go func() {
|
|
g.ProjectInitStatus = true
|
|
}()
|
|
}
|