代码拉取完成,页面将自动刷新
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,
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。