diff --git a/comm/const.go b/comm/const.go index c234e0d5c..be9e6784b 100644 --- a/comm/const.go +++ b/comm/const.go @@ -29,12 +29,12 @@ const ( //模块名定义处 const ( ModuleGate core.M_Modules = "gateway" //gate模块 网关服务模块 - ModuleWeb core.M_Modules = "web" //web模块 + ModuleGM core.M_Modules = "gm" //gm模块 ModuleUser core.M_Modules = "user" //用户模块 ModulePack core.M_Modules = "pack" //背包模块 ModuleMail core.M_Modules = "mail" //邮件模块 ModuleFriend core.M_Modules = "friend" //好友模块 - ModuleLogModel core.M_Modules = "model" //日志模块 + ModuleMgoLog core.M_Modules = "mgolog" //日志模块 ModuleEquipment core.M_Modules = "equipment" //装备模块 ModuleHero core.M_Modules = "hero" //英雄模块 ModuleForum core.M_Modules = "forum" //论坛模块 diff --git a/comm/usersession.go b/comm/usersession.go index 75087048b..d325bb00c 100644 --- a/comm/usersession.go +++ b/comm/usersession.go @@ -118,7 +118,7 @@ func (this *UserSession) UnBind() (err error) { //向用户发送消息 func (this *UserSession) SendMsg(mainType, subType string, msg proto.Message) (err error) { - log.Debugf("SendMsg to UserId:[%s] Data: %v", this.UserId, msg) + // log.Debugf("SendMsg to UserId:[%s] Data: %v", this.UserId, msg) data, _ := anypb.New(msg) this.msgqueue = append(this.msgqueue, &pb.UserMessage{ MainType: mainType, diff --git a/lego/core/cbase/servicebase.go b/lego/core/cbase/servicebase.go index fe7972353..86f6cac58 100644 --- a/lego/core/cbase/servicebase.go +++ b/lego/core/cbase/servicebase.go @@ -99,16 +99,14 @@ func (this *ServiceBase) Run(mod ...core.IModule) { mi: v, closeSig: make(chan bool, 1), } - - log.Warnf("注册模块【%s】 对应的配置信息", v.GetType()) } else { this.modules[v.GetType()] = &defaultModule{ seetring: make(map[string]interface{}), mi: v, closeSig: make(chan bool, 1), } - //log.Warnf("注册模块【%s】 没有对应的配置信息", v.GetType()) } + log.Infof("注册模块【%s】", v.GetType()) } for _, v := range this.modules { //序列化每一个模块的参数对象 完成模块的初始化 过程 options := v.mi.NewOptions() diff --git a/modules/gm/module.go b/modules/gm/module.go index e901e6b83..eb5b7368e 100644 --- a/modules/gm/module.go +++ b/modules/gm/module.go @@ -29,7 +29,7 @@ type GM struct { //模块名 func (this *GM) GetType() core.M_Modules { - return comm.ModuleWeb + return comm.ModuleGM } //模块自定义参数 diff --git a/modules/items/api_getlist.go b/modules/items/api_getlist.go index b93e45ab3..6239280d1 100644 --- a/modules/items/api_getlist.go +++ b/modules/items/api_getlist.go @@ -29,8 +29,12 @@ func (this *apiComp) Getlist(session comm.IUserSession, req *pb.ItemsGetlistReq) session.SendMsg(string(this.module.GetType()), "getlist", &pb.ItemsGetlistResp{Grids: grids}) if code == pb.ErrorCode_Success { go func() { //异步处理修改数据 - this.module.modelItems.Pack_UpdateUserPack(session.GetUserId(), modifys...) - this.module.modelItems.Pack_DeleteUserPack(session.GetUserId(), dels...) + if len(modifys) > 0 { + this.module.modelItems.Pack_UpdateUserPack(session.GetUserId(), modifys...) + } + if len(dels) > 0 { + this.module.modelItems.Pack_DeleteUserPack(session.GetUserId(), dels...) + } }() } }() diff --git a/modules/dbservice/core.go b/modules/mgolog/core.go similarity index 94% rename from modules/dbservice/core.go rename to modules/mgolog/core.go index 6c7345fa7..56bc17551 100644 --- a/modules/dbservice/core.go +++ b/modules/mgolog/core.go @@ -1,4 +1,4 @@ -package dbservice +package mgolog import ( "go_dreamfactory/lego/core" diff --git a/modules/dbservice/db_comp.go b/modules/mgolog/db_comp.go similarity index 99% rename from modules/dbservice/db_comp.go rename to modules/mgolog/db_comp.go index 366d945e1..858810e0e 100644 --- a/modules/dbservice/db_comp.go +++ b/modules/mgolog/db_comp.go @@ -1,4 +1,4 @@ -package dbservice +package mgolog import ( "context" diff --git a/modules/dbservice/module.go b/modules/mgolog/module.go similarity index 53% rename from modules/dbservice/module.go rename to modules/mgolog/module.go index 3e8a81eaa..5259cf42a 100644 --- a/modules/dbservice/module.go +++ b/modules/mgolog/module.go @@ -1,4 +1,4 @@ -package dbservice +package mgolog import ( "go_dreamfactory/comm" @@ -7,26 +7,26 @@ import ( ) func NewModule() core.IModule { - m := new(DBService) + m := new(MgoLog) return m } -type DBService struct { +type MgoLog struct { cbase.ModuleBase db_comp *DB_Comp } -func (this *DBService) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { +func (this *MgoLog) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { err = this.ModuleBase.Init(service, module, options) return } -func (this *DBService) GetType() core.M_Modules { - return comm.ModuleLogModel +func (this *MgoLog) GetType() core.M_Modules { + return comm.ModuleMgoLog } -func (this *DBService) OnInstallComp() { +func (this *MgoLog) OnInstallComp() { this.ModuleBase.OnInstallComp() this.db_comp = this.RegisterComp(new(DB_Comp)).(*DB_Comp) } diff --git a/services/comp_gateroute.go b/services/comp_gateroute.go index 10f1c46f0..cf49817d0 100644 --- a/services/comp_gateroute.go +++ b/services/comp_gateroute.go @@ -15,11 +15,31 @@ import ( "go_dreamfactory/lego/core/cbase" "go_dreamfactory/lego/sys/event" "go_dreamfactory/lego/sys/log" + "go_dreamfactory/lego/utils/mapstructure" "google.golang.org/protobuf/proto" "google.golang.org/protobuf/types/known/anypb" ) +//用户协议处理函数注册的反射对象 +type msghandle struct { + rcvr reflect.Value + msgType reflect.Type //消息请求类型 + handle reflect.Method //处理函数 +} + +//组件参数 +type CompOptions struct { + Debug bool +} + +func (this *CompOptions) LoadConfig(settings map[string]interface{}) (err error) { + if settings != nil { + err = mapstructure.Decode(settings, this) + } + return +} + /* 服务网关组件 用于接收网关服务发送过来的消息 */ @@ -29,16 +49,10 @@ func NewGateRouteComp() comm.ISC_GateRouteComp { return comp } -//用户协议处理函数注册的反射对象 -type msghandle struct { - rcvr reflect.Value - msgType reflect.Type //消息请求类型 - handle reflect.Method //处理函数 -} - //服务网关组件 type SCompGateRoute struct { cbase.ServiceCompBase + options *CompOptions service base.IRPCXService //rpc服务对象 通过这个对象可以发布服务和调用其他服务的接口 mrlock sync.RWMutex //msghandles 对象的锁 msghandles map[string]*msghandle //处理函数的管理对象 @@ -50,9 +64,14 @@ func (this *SCompGateRoute) GetName() core.S_Comps { return comm.SC_ServiceGateRouteComp } +func (this *SCompGateRoute) NewOptions() (options core.ICompOptions) { + return new(CompOptions) +} + //组件初始化函数 func (this *SCompGateRoute) Init(service core.IService, comp core.IServiceComp, options core.ICompOptions) (err error) { err = this.ServiceCompBase.Init(service, comp, options) + this.options = options.(*CompOptions) this.service = service.(base.IRPCXService) this.msghandles = make(map[string]*msghandle) this.pools = sync.Pool{ @@ -126,7 +145,6 @@ func (this *SCompGateRoute) ReceiveMsg(ctx context.Context, args *pb.AgentMessag //执行处理流 stime := time.Now() handlereturn := msghandle.handle.Func.Call([]reflect.Value{msghandle.rcvr, reflect.ValueOf(session), reflect.ValueOf(msg)}) - log.Debugf("[Handle Api] consumetime:%v method:%s uid:%s msg:%v", time.Since(stime), method, args.UserId, msg) errcode := pb.ErrorCode(handlereturn[0].Int()) errdata := handlereturn[1].Interface() if errcode != pb.ErrorCode_Success { //处理返货错误码 返回用户错误信息 @@ -139,6 +157,9 @@ func (this *SCompGateRoute) ReceiveMsg(ctx context.Context, args *pb.AgentMessag } } else { reply.Reply = session.Polls() + if this.options.Debug { + log.Debugf("[Handle Api] consumetime:%v method:%s uid:%s msg:%v reply:%v", time.Since(stime), method, args.UserId, msg, reply) + } } } else { //未找到消息处理函数 log.Errorf("[Handle Api] no found handle %s", method) diff --git a/services/dbservice/main.go b/services/mainte/main.go similarity index 80% rename from services/dbservice/main.go rename to services/mainte/main.go index 84e957a20..9a1d6db47 100644 --- a/services/dbservice/main.go +++ b/services/mainte/main.go @@ -3,7 +3,8 @@ package main import ( "flag" "fmt" - "go_dreamfactory/modules/dbservice" + "go_dreamfactory/modules/gm" + "go_dreamfactory/modules/mgolog" "go_dreamfactory/services" "go_dreamfactory/sys/cache" "go_dreamfactory/sys/db" @@ -15,11 +16,11 @@ import ( ) /* - 服务类型:dbservice - 服务描述:处理梦工厂的具体业务需求,包含 user,pack,mail,friend...功能业务模块 + 服务类型:mainte + 服务描述:数据库维护以及GM后台接口 服务 */ var ( - conf = flag.String("conf", "./conf/dbservice.yaml", "获取需要启动的服务配置文件") //启动服务的Id + conf = flag.String("conf", "./conf/mainte.yaml", "获取需要启动的服务配置文件") //启动服务的Id ) /*服务启动的入口函数*/ @@ -33,9 +34,9 @@ func main() { //services.NewGateRouteComp(), //此服务需要接受用户的消息 需要装备网关组件 ) lego.Run(s, //运行模块 - dbservice.NewModule(), + mgolog.NewModule(), + gm.NewModule(), ) - } func NewService(ops ...rpcx.Option) core.IService { diff --git a/services/web/main.go b/services/web/main.go deleted file mode 100644 index a609ec6e9..000000000 --- a/services/web/main.go +++ /dev/null @@ -1,61 +0,0 @@ -package main - -import ( - "flag" - "fmt" - "go_dreamfactory/modules/web" - "go_dreamfactory/services" - "go_dreamfactory/sys/cache" - "go_dreamfactory/sys/db" - - "go_dreamfactory/lego" - "go_dreamfactory/lego/base/rpcx" - "go_dreamfactory/lego/core" - "go_dreamfactory/lego/sys/log" -) - -/* - 服务类型:web - 服务描述:提供一些http服务,方便后期维护和开发过程中的测试,只包含 web 业务模块 -*/ -var ( - conf = flag.String("conf", "./conf/web_1.yaml", "获取需要启动的服务配置文件") //启动服务的Id -) - -func main() { - flag.Parse() - s := NewService( - rpcx.SetConfPath(*conf), - rpcx.SetVersion("1.0.0.0"), - ) - s.OnInstallComp( //装备组件 - ) - lego.Run(s, //运行模块 - web.NewModule(), - ) - -} - -func NewService(ops ...rpcx.Option) core.IService { - s := new(Service) - s.Configure(ops...) - return s -} - -type Service struct { - services.ServiceBase -} - -func (this *Service) InitSys() { - this.ServiceBase.InitSys() - if err := cache.OnInit(this.GetSettings().Sys["cache"]); err != nil { - panic(fmt.Sprintf("init sys.cache err: %s", err.Error())) - } else { - log.Infof("init sys.cache success!") - } - if err := db.OnInit(this.GetSettings().Sys["db"]); err != nil { - panic(fmt.Sprintf("init sys.db err: %s", err.Error())) - } else { - log.Infof("init sys.db success!") - } -} diff --git a/services/worker/main.go b/services/worker/main.go index 0519b14c6..9e2e6c9d1 100644 --- a/services/worker/main.go +++ b/services/worker/main.go @@ -27,7 +27,7 @@ import ( 服务描述:处理梦工厂的具体业务需求,包含 user,pack,mail,friend...功能业务模块 */ var ( - conf = flag.String("conf", "./conf/worker.yaml", "获取需要启动的服务配置文件") //启动服务的Id + conf = flag.String("conf", "./conf/worker_1.yaml", "获取需要启动的服务配置文件") //启动服务的Id ) /*服务启动的入口函数*/