2 Star 2 Fork 4

联犀/core

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
serviceContext.go 2.64 KB
一键复制 编辑 原始数据 按行查看 历史
杨磊 提交于 2024-10-10 21:56 . feat: 更新mod
package svc
import (
"gitee.com/unitedrhino/core/service/syssvr/internal/config"
"gitee.com/unitedrhino/core/service/syssvr/internal/repo/cache"
"gitee.com/unitedrhino/core/service/syssvr/internal/repo/relationDB"
"gitee.com/unitedrhino/core/service/syssvr/pb/sys"
"gitee.com/unitedrhino/share/caches"
"gitee.com/unitedrhino/share/clients/smsClient"
"gitee.com/unitedrhino/share/domain/tenant"
"gitee.com/unitedrhino/share/eventBus"
"gitee.com/unitedrhino/share/oss"
"gitee.com/unitedrhino/share/stores"
"gitee.com/unitedrhino/share/utils"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/core/stores/kv"
"os"
)
type ServiceContext struct {
Config config.Config
ProjectID *utils.SnowFlake
AreaID *utils.SnowFlake
UserID *utils.SnowFlake
Slot *cache.Slot
OssClient *oss.Client
Store kv.Store
PwdCheck *cache.PwdCheck
Captcha *cache.Captcha
Cm *ClientsManage
FastEvent *eventBus.FastEvent
UserTokenInfo *cache.UserToken
TenantCache *caches.Cache[tenant.Info, string]
TenantConfigCache *caches.Cache[sys.TenantConfig, string]
ProjectCache *caches.Cache[sys.ProjectInfo, int64]
UserCache *caches.Cache[sys.UserInfo, int64]
ApiCache *caches.Cache[relationDB.SysApiInfo, string]
RoleAccessCache *caches.Cache[map[int64]struct{}, string]
Sms *smsClient.Sms
}
func NewServiceContext(c config.Config) *ServiceContext {
stores.InitConn(c.Database)
err := relationDB.Migrate(c.Database)
if err != nil {
logx.Error("syssvr 数据库初始化失败 err", err)
os.Exit(-1)
}
// 自动迁移数据库
nodeID := utils.GetNodeID(c.CacheRedis, c.Name)
ProjectID := utils.NewSnowFlake(nodeID)
AreaID := utils.NewSnowFlake(nodeID)
nodeId := utils.GetNodeID(c.CacheRedis, c.Name)
UserID := utils.NewSnowFlake(nodeId)
store := kv.NewStore(c.CacheRedis)
ossClient, err := oss.NewOssClient(c.OssConf)
if err != nil {
logx.Errorf("NewOss err err:%v", err)
os.Exit(-1)
}
serverMsg, err := eventBus.NewFastEvent(c.Event, c.Name, nodeID)
logx.Must(err)
sms, err := smsClient.NewSms(c.Sms)
logx.Must(err)
userTokenInfo, err := cache.NewUserToken(serverMsg)
logx.Must(err)
return &ServiceContext{
FastEvent: serverMsg,
Captcha: cache.NewCaptcha(store),
PwdCheck: cache.NewPwdCheck(store),
Slot: cache.NewSlot(),
Cm: NewClients(c),
Config: c,
ProjectID: ProjectID,
OssClient: ossClient,
AreaID: AreaID,
UserID: UserID,
Store: store,
Sms: sms,
UserTokenInfo: userTokenInfo,
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/unitedrhino/core.git
git@gitee.com:unitedrhino/core.git
unitedrhino
core
core
v0.2.4

搜索帮助