1 Star 0 Fork 1

iThings/core

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
serviceContext.go 6.97 KB
一键复制 编辑 原始数据 按行查看 历史
杨磊 提交于 2024-08-12 18:07 . feat: 完善项目
package svc
import (
"gitee.com/i-Things/core/service/apisvr/exportMiddleware"
"gitee.com/i-Things/core/service/apisvr/internal/config"
"gitee.com/i-Things/core/service/syssvr/client/accessmanage"
app "gitee.com/i-Things/core/service/syssvr/client/appmanage"
"gitee.com/i-Things/core/service/syssvr/client/areamanage"
"gitee.com/i-Things/core/service/syssvr/client/common"
"gitee.com/i-Things/core/service/syssvr/client/datamanage"
"gitee.com/i-Things/core/service/syssvr/client/dictmanage"
"gitee.com/i-Things/core/service/syssvr/client/log"
module "gitee.com/i-Things/core/service/syssvr/client/modulemanage"
"gitee.com/i-Things/core/service/syssvr/client/notifymanage"
"gitee.com/i-Things/core/service/syssvr/client/ops"
"gitee.com/i-Things/core/service/syssvr/client/projectmanage"
role "gitee.com/i-Things/core/service/syssvr/client/rolemanage"
tenant "gitee.com/i-Things/core/service/syssvr/client/tenantmanage"
user "gitee.com/i-Things/core/service/syssvr/client/usermanage"
"gitee.com/i-Things/core/service/syssvr/sysExport"
"gitee.com/i-Things/core/service/syssvr/sysdirect"
"gitee.com/i-Things/core/service/timed/timedjobsvr/client/timedmanage"
"gitee.com/i-Things/core/service/timed/timedjobsvr/timedjobdirect"
"gitee.com/i-Things/core/service/timed/timedschedulersvr/client/timedscheduler"
"gitee.com/i-Things/core/service/timed/timedschedulersvr/timedschedulerdirect"
"gitee.com/i-Things/share/caches"
"gitee.com/i-Things/share/conf"
"gitee.com/i-Things/share/ctxs"
"gitee.com/i-Things/share/eventBus"
"gitee.com/i-Things/share/oss"
"gitee.com/i-Things/share/utils"
"gitee.com/i-Things/share/verify"
ws "gitee.com/i-Things/share/websocket"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/rest"
"github.com/zeromicro/go-zero/zrpc"
"os"
"time"
)
type SvrClient struct {
TenantRpc tenant.TenantManage
UserRpc user.UserManage
RoleRpc role.RoleManage
AppRpc app.AppManage
ModuleRpc module.ModuleManage
LogRpc log.Log
ProjectM projectmanage.ProjectManage
AreaM areamanage.AreaManage
DictM dictmanage.DictManage
NotifyM notifymanage.NotifyManage
Common common.Common
Slot sysExport.SlotCacheT
AccessRpc accessmanage.AccessManage
DataM datamanage.DataManage
Timedscheduler timedscheduler.Timedscheduler
TimedJob timedmanage.TimedManage
Ops ops.Ops
}
type ServiceContext struct {
SvrClient
Ws *ws.Server
Config config.Config
UserCache sysExport.UserCacheT
CheckTokenWare rest.Middleware
InitCtxsWare rest.Middleware
Captcha *verify.Captcha
OssClient *oss.Client
NodeID int64
ServerMsg *eventBus.FastEvent
}
func NewServiceContext(c config.Config) *ServiceContext {
var (
appRpc app.AppManage
projectM projectmanage.ProjectManage
areaM areamanage.AreaManage
sysCommon common.Common
timedSchedule timedscheduler.Timedscheduler
timedJob timedmanage.TimedManage
tenantM tenant.TenantManage
DataM datamanage.DataManage
DictM dictmanage.DictManage
accessM accessmanage.AccessManage
Ops ops.Ops
NotifyM notifymanage.NotifyManage
)
var ur user.UserManage
var ro role.RoleManage
var me module.ModuleManage
var lo log.Log
caches.InitStore(c.CacheRedis)
nodeID := utils.GetNodeID(c.CacheRedis, c.Name)
serverMsg, err := eventBus.NewFastEvent(c.Event, c.Name, nodeID)
logx.Must(err)
ws.StartWsDp(false, nodeID, serverMsg, c.CacheRedis)
if c.SysRpc.Enable {
if c.SysRpc.Mode == conf.ClientModeGrpc {
projectM = projectmanage.NewProjectManage(zrpc.MustNewClient(c.SysRpc.Conf))
areaM = areamanage.NewAreaManage(zrpc.MustNewClient(c.SysRpc.Conf))
ur = user.NewUserManage(zrpc.MustNewClient(c.SysRpc.Conf))
ro = role.NewRoleManage(zrpc.MustNewClient(c.SysRpc.Conf))
me = module.NewModuleManage(zrpc.MustNewClient(c.SysRpc.Conf))
lo = log.NewLog(zrpc.MustNewClient(c.SysRpc.Conf))
sysCommon = common.NewCommon(zrpc.MustNewClient(c.SysRpc.Conf))
appRpc = app.NewAppManage(zrpc.MustNewClient(c.SysRpc.Conf))
tenantM = tenant.NewTenantManage(zrpc.MustNewClient(c.SysRpc.Conf))
DataM = datamanage.NewDataManage(zrpc.MustNewClient(c.SysRpc.Conf))
accessM = accessmanage.NewAccessManage(zrpc.MustNewClient(c.SysRpc.Conf))
DictM = dictmanage.NewDictManage(zrpc.MustNewClient(c.SysRpc.Conf))
Ops = ops.NewOps(zrpc.MustNewClient(c.SysRpc.Conf))
NotifyM = notifymanage.NewNotifyManage(zrpc.MustNewClient(c.SysRpc.Conf))
} else {
projectM = sysdirect.NewProjectManage(c.SysRpc.RunProxy)
areaM = sysdirect.NewAreaManage(c.SysRpc.RunProxy)
ur = sysdirect.NewUser(c.SysRpc.RunProxy)
ro = sysdirect.NewRole(c.SysRpc.RunProxy)
me = sysdirect.NewModule(c.SysRpc.RunProxy)
lo = sysdirect.NewLog(c.SysRpc.RunProxy)
sysCommon = sysdirect.NewCommon(c.SysRpc.RunProxy)
appRpc = sysdirect.NewApp(c.SysRpc.RunProxy)
tenantM = sysdirect.NewTenantManage(c.SysRpc.RunProxy)
DataM = sysdirect.NewData(c.SysRpc.RunProxy)
accessM = sysdirect.NewAccess(c.SysRpc.RunProxy)
DictM = sysdirect.NewDict(c.SysRpc.RunProxy)
Ops = sysdirect.NewOps(c.SysRpc.RunProxy)
NotifyM = sysdirect.NewNotify(c.SysRpc.RunProxy)
}
}
if c.TimedSchedulerRpc.Enable {
if c.TimedSchedulerRpc.Mode == conf.ClientModeGrpc {
timedSchedule = timedscheduler.NewTimedscheduler(zrpc.MustNewClient(c.TimedSchedulerRpc.Conf))
} else {
timedSchedule = timedschedulerdirect.NewScheduler(c.TimedSchedulerRpc.RunProxy)
}
}
if c.TimedJobRpc.Enable {
if c.TimedJobRpc.Mode == conf.ClientModeGrpc {
timedJob = timedmanage.NewTimedManage(zrpc.MustNewClient(c.TimedJobRpc.Conf))
} else {
timedJob = timedjobdirect.NewTimedJob(c.TimedJobRpc.RunProxy)
}
}
Slot, err := sysExport.NewSlotCache(sysCommon)
logx.Must(err)
ossClient, err := oss.NewOssClient(c.OssConf)
if err != nil {
logx.Errorf("NewOss err err:%v", err)
os.Exit(-1)
}
userCache, err := sysExport.NewUserInfoCache(ur, serverMsg)
logx.Must(err)
captcha := verify.NewCaptcha(c.Captcha.ImgHeight, c.Captcha.ImgWidth,
c.Captcha.KeyLong, c.CacheRedis, time.Duration(c.Captcha.KeepTime)*time.Second)
return &ServiceContext{
Config: c,
CheckTokenWare: exportMiddleware.NewCheckTokenWareMiddleware(ur, ro, tenantM, lo).Handle,
InitCtxsWare: ctxs.InitMiddleware,
UserCache: userCache,
Captcha: captcha,
OssClient: ossClient,
Ws: ws.MustNewServer(c.RestConf),
NodeID: nodeID,
ServerMsg: serverMsg,
SvrClient: SvrClient{
TenantRpc: tenantM,
AppRpc: appRpc,
UserRpc: ur,
RoleRpc: ro,
ModuleRpc: me,
Slot: Slot,
LogRpc: lo,
AccessRpc: accessM,
NotifyM: NotifyM,
Timedscheduler: timedSchedule,
TimedJob: timedJob,
ProjectM: projectM,
AreaM: areaM,
DataM: DataM,
DictM: DictM,
Common: sysCommon,
Ops: Ops,
},
//OSS: ossClient,
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/i-Things/core.git
git@gitee.com:i-Things/core.git
i-Things
core
core
v0.1.6

搜索帮助