伤处模块日志优化
This commit is contained in:
parent
2bb353817e
commit
acbeae031c
@ -29,12 +29,12 @@ const (
|
|||||||
//模块名定义处
|
//模块名定义处
|
||||||
const (
|
const (
|
||||||
ModuleGate core.M_Modules = "gateway" //gate模块 网关服务模块
|
ModuleGate core.M_Modules = "gateway" //gate模块 网关服务模块
|
||||||
ModuleWeb core.M_Modules = "web" //web模块
|
ModuleGM core.M_Modules = "gm" //gm模块
|
||||||
ModuleUser core.M_Modules = "user" //用户模块
|
ModuleUser core.M_Modules = "user" //用户模块
|
||||||
ModulePack core.M_Modules = "pack" //背包模块
|
ModulePack core.M_Modules = "pack" //背包模块
|
||||||
ModuleMail core.M_Modules = "mail" //邮件模块
|
ModuleMail core.M_Modules = "mail" //邮件模块
|
||||||
ModuleFriend core.M_Modules = "friend" //好友模块
|
ModuleFriend core.M_Modules = "friend" //好友模块
|
||||||
ModuleLogModel core.M_Modules = "model" //日志模块
|
ModuleMgoLog core.M_Modules = "mgolog" //日志模块
|
||||||
ModuleEquipment core.M_Modules = "equipment" //装备模块
|
ModuleEquipment core.M_Modules = "equipment" //装备模块
|
||||||
ModuleHero core.M_Modules = "hero" //英雄模块
|
ModuleHero core.M_Modules = "hero" //英雄模块
|
||||||
ModuleForum core.M_Modules = "forum" //论坛模块
|
ModuleForum core.M_Modules = "forum" //论坛模块
|
||||||
|
@ -118,7 +118,7 @@ func (this *UserSession) UnBind() (err error) {
|
|||||||
|
|
||||||
//向用户发送消息
|
//向用户发送消息
|
||||||
func (this *UserSession) SendMsg(mainType, subType string, msg proto.Message) (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)
|
data, _ := anypb.New(msg)
|
||||||
this.msgqueue = append(this.msgqueue, &pb.UserMessage{
|
this.msgqueue = append(this.msgqueue, &pb.UserMessage{
|
||||||
MainType: mainType,
|
MainType: mainType,
|
||||||
|
@ -99,16 +99,14 @@ func (this *ServiceBase) Run(mod ...core.IModule) {
|
|||||||
mi: v,
|
mi: v,
|
||||||
closeSig: make(chan bool, 1),
|
closeSig: make(chan bool, 1),
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Warnf("注册模块【%s】 对应的配置信息", v.GetType())
|
|
||||||
} else {
|
} else {
|
||||||
this.modules[v.GetType()] = &defaultModule{
|
this.modules[v.GetType()] = &defaultModule{
|
||||||
seetring: make(map[string]interface{}),
|
seetring: make(map[string]interface{}),
|
||||||
mi: v,
|
mi: v,
|
||||||
closeSig: make(chan bool, 1),
|
closeSig: make(chan bool, 1),
|
||||||
}
|
}
|
||||||
//log.Warnf("注册模块【%s】 没有对应的配置信息", v.GetType())
|
|
||||||
}
|
}
|
||||||
|
log.Infof("注册模块【%s】", v.GetType())
|
||||||
}
|
}
|
||||||
for _, v := range this.modules { //序列化每一个模块的参数对象 完成模块的初始化 过程
|
for _, v := range this.modules { //序列化每一个模块的参数对象 完成模块的初始化 过程
|
||||||
options := v.mi.NewOptions()
|
options := v.mi.NewOptions()
|
||||||
|
@ -29,7 +29,7 @@ type GM struct {
|
|||||||
|
|
||||||
//模块名
|
//模块名
|
||||||
func (this *GM) GetType() core.M_Modules {
|
func (this *GM) GetType() core.M_Modules {
|
||||||
return comm.ModuleWeb
|
return comm.ModuleGM
|
||||||
}
|
}
|
||||||
|
|
||||||
//模块自定义参数
|
//模块自定义参数
|
||||||
|
@ -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})
|
session.SendMsg(string(this.module.GetType()), "getlist", &pb.ItemsGetlistResp{Grids: grids})
|
||||||
if code == pb.ErrorCode_Success {
|
if code == pb.ErrorCode_Success {
|
||||||
go func() { //异步处理修改数据
|
go func() { //异步处理修改数据
|
||||||
this.module.modelItems.Pack_UpdateUserPack(session.GetUserId(), modifys...)
|
if len(modifys) > 0 {
|
||||||
this.module.modelItems.Pack_DeleteUserPack(session.GetUserId(), dels...)
|
this.module.modelItems.Pack_UpdateUserPack(session.GetUserId(), modifys...)
|
||||||
|
}
|
||||||
|
if len(dels) > 0 {
|
||||||
|
this.module.modelItems.Pack_DeleteUserPack(session.GetUserId(), dels...)
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package dbservice
|
package mgolog
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go_dreamfactory/lego/core"
|
"go_dreamfactory/lego/core"
|
@ -1,4 +1,4 @@
|
|||||||
package dbservice
|
package mgolog
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
@ -1,4 +1,4 @@
|
|||||||
package dbservice
|
package mgolog
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go_dreamfactory/comm"
|
"go_dreamfactory/comm"
|
||||||
@ -7,26 +7,26 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func NewModule() core.IModule {
|
func NewModule() core.IModule {
|
||||||
m := new(DBService)
|
m := new(MgoLog)
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
type DBService struct {
|
type MgoLog struct {
|
||||||
cbase.ModuleBase
|
cbase.ModuleBase
|
||||||
db_comp *DB_Comp
|
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)
|
err = this.ModuleBase.Init(service, module, options)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *DBService) GetType() core.M_Modules {
|
func (this *MgoLog) GetType() core.M_Modules {
|
||||||
return comm.ModuleLogModel
|
return comm.ModuleMgoLog
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *DBService) OnInstallComp() {
|
func (this *MgoLog) OnInstallComp() {
|
||||||
this.ModuleBase.OnInstallComp()
|
this.ModuleBase.OnInstallComp()
|
||||||
this.db_comp = this.RegisterComp(new(DB_Comp)).(*DB_Comp)
|
this.db_comp = this.RegisterComp(new(DB_Comp)).(*DB_Comp)
|
||||||
}
|
}
|
@ -15,11 +15,31 @@ import (
|
|||||||
"go_dreamfactory/lego/core/cbase"
|
"go_dreamfactory/lego/core/cbase"
|
||||||
"go_dreamfactory/lego/sys/event"
|
"go_dreamfactory/lego/sys/event"
|
||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
|
"go_dreamfactory/lego/utils/mapstructure"
|
||||||
|
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
"google.golang.org/protobuf/types/known/anypb"
|
"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
|
return comp
|
||||||
}
|
}
|
||||||
|
|
||||||
//用户协议处理函数注册的反射对象
|
|
||||||
type msghandle struct {
|
|
||||||
rcvr reflect.Value
|
|
||||||
msgType reflect.Type //消息请求类型
|
|
||||||
handle reflect.Method //处理函数
|
|
||||||
}
|
|
||||||
|
|
||||||
//服务网关组件
|
//服务网关组件
|
||||||
type SCompGateRoute struct {
|
type SCompGateRoute struct {
|
||||||
cbase.ServiceCompBase
|
cbase.ServiceCompBase
|
||||||
|
options *CompOptions
|
||||||
service base.IRPCXService //rpc服务对象 通过这个对象可以发布服务和调用其他服务的接口
|
service base.IRPCXService //rpc服务对象 通过这个对象可以发布服务和调用其他服务的接口
|
||||||
mrlock sync.RWMutex //msghandles 对象的锁
|
mrlock sync.RWMutex //msghandles 对象的锁
|
||||||
msghandles map[string]*msghandle //处理函数的管理对象
|
msghandles map[string]*msghandle //处理函数的管理对象
|
||||||
@ -50,9 +64,14 @@ func (this *SCompGateRoute) GetName() core.S_Comps {
|
|||||||
return comm.SC_ServiceGateRouteComp
|
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) {
|
func (this *SCompGateRoute) Init(service core.IService, comp core.IServiceComp, options core.ICompOptions) (err error) {
|
||||||
err = this.ServiceCompBase.Init(service, comp, options)
|
err = this.ServiceCompBase.Init(service, comp, options)
|
||||||
|
this.options = options.(*CompOptions)
|
||||||
this.service = service.(base.IRPCXService)
|
this.service = service.(base.IRPCXService)
|
||||||
this.msghandles = make(map[string]*msghandle)
|
this.msghandles = make(map[string]*msghandle)
|
||||||
this.pools = sync.Pool{
|
this.pools = sync.Pool{
|
||||||
@ -126,7 +145,6 @@ func (this *SCompGateRoute) ReceiveMsg(ctx context.Context, args *pb.AgentMessag
|
|||||||
//执行处理流
|
//执行处理流
|
||||||
stime := time.Now()
|
stime := time.Now()
|
||||||
handlereturn := msghandle.handle.Func.Call([]reflect.Value{msghandle.rcvr, reflect.ValueOf(session), reflect.ValueOf(msg)})
|
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())
|
errcode := pb.ErrorCode(handlereturn[0].Int())
|
||||||
errdata := handlereturn[1].Interface()
|
errdata := handlereturn[1].Interface()
|
||||||
if errcode != pb.ErrorCode_Success { //处理返货错误码 返回用户错误信息
|
if errcode != pb.ErrorCode_Success { //处理返货错误码 返回用户错误信息
|
||||||
@ -139,6 +157,9 @@ func (this *SCompGateRoute) ReceiveMsg(ctx context.Context, args *pb.AgentMessag
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
reply.Reply = session.Polls()
|
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 { //未找到消息处理函数
|
} else { //未找到消息处理函数
|
||||||
log.Errorf("[Handle Api] no found handle %s", method)
|
log.Errorf("[Handle Api] no found handle %s", method)
|
||||||
|
@ -3,7 +3,8 @@ package main
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"go_dreamfactory/modules/dbservice"
|
"go_dreamfactory/modules/gm"
|
||||||
|
"go_dreamfactory/modules/mgolog"
|
||||||
"go_dreamfactory/services"
|
"go_dreamfactory/services"
|
||||||
"go_dreamfactory/sys/cache"
|
"go_dreamfactory/sys/cache"
|
||||||
"go_dreamfactory/sys/db"
|
"go_dreamfactory/sys/db"
|
||||||
@ -15,11 +16,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
服务类型:dbservice
|
服务类型:mainte
|
||||||
服务描述:处理梦工厂的具体业务需求,包含 user,pack,mail,friend...功能业务模块
|
服务描述:数据库维护以及GM后台接口 服务
|
||||||
*/
|
*/
|
||||||
var (
|
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(), //此服务需要接受用户的消息 需要装备网关组件
|
//services.NewGateRouteComp(), //此服务需要接受用户的消息 需要装备网关组件
|
||||||
)
|
)
|
||||||
lego.Run(s, //运行模块
|
lego.Run(s, //运行模块
|
||||||
dbservice.NewModule(),
|
mgolog.NewModule(),
|
||||||
|
gm.NewModule(),
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewService(ops ...rpcx.Option) core.IService {
|
func NewService(ops ...rpcx.Option) core.IService {
|
@ -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!")
|
|
||||||
}
|
|
||||||
}
|
|
@ -27,7 +27,7 @@ import (
|
|||||||
服务描述:处理梦工厂的具体业务需求,包含 user,pack,mail,friend...功能业务模块
|
服务描述:处理梦工厂的具体业务需求,包含 user,pack,mail,friend...功能业务模块
|
||||||
*/
|
*/
|
||||||
var (
|
var (
|
||||||
conf = flag.String("conf", "./conf/worker.yaml", "获取需要启动的服务配置文件") //启动服务的Id
|
conf = flag.String("conf", "./conf/worker_1.yaml", "获取需要启动的服务配置文件") //启动服务的Id
|
||||||
)
|
)
|
||||||
|
|
||||||
/*服务启动的入口函数*/
|
/*服务启动的入口函数*/
|
||||||
|
Loading…
Reference in New Issue
Block a user