diff --git a/comm/core.go b/comm/core.go index 41e3eec8c..ccaa87978 100644 --- a/comm/core.go +++ b/comm/core.go @@ -12,9 +12,9 @@ const ( ) const ( - SM_GateModule core.M_Modules = "SM_GateModule" //gate模块 网关服务模块 - SM_WebModule core.M_Modules = "SM_WebModule" //web模块 - SM_LoginModule core.M_Modules = "SM_LoginModule" //web模块 + SM_GateModule core.M_Modules = "gateway" //gate模块 网关服务模块 + SM_WebModule core.M_Modules = "web" //web模块 + SM_LoginModule core.M_Modules = "login" //web模块 ) const ( //Rpc diff --git a/modules/gate_comp.go b/modules/gate_comp.go index 652eb477d..a8de11d18 100644 --- a/modules/gate_comp.go +++ b/modules/gate_comp.go @@ -2,8 +2,10 @@ package modules import ( "context" + "fmt" "go_dreamfactory/comm" "reflect" + "strings" "unicode" "unicode/utf8" @@ -22,12 +24,14 @@ var typeOfError = reflect.TypeOf((*error)(nil)).Elem() type MComp_GateComp struct { cbase.ModuleCompBase service base.IRPCXService + module core.IModule comp core.IModuleComp } func (this *MComp_GateComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { this.ModuleCompBase.Init(service, module, comp, options) this.service = service.(base.IRPCXService) + this.module = module this.comp = comp return } @@ -86,7 +90,7 @@ func (this *MComp_GateComp) suitableMethods(scomp comm.ISC_GateRouteComp, typ re if returnType := mtype.Out(0); returnType != typeOfError { continue } - scomp.RegisterRoute(mname, reflect.ValueOf(this.comp), replyType, method) + scomp.RegisterRoute(fmt.Sprintf("%s.%s", this.module.GetType(), strings.ToLower(mname)), reflect.ValueOf(this.comp), replyType, method) } } diff --git a/modules/web/api_comp.go b/modules/web/api_comp.go new file mode 100644 index 000000000..bd707c186 --- /dev/null +++ b/modules/web/api_comp.go @@ -0,0 +1,26 @@ +package web + +import ( + "github.com/liwei1dao/lego/core" + "github.com/liwei1dao/lego/core/cbase" + "github.com/liwei1dao/lego/sys/gin" + "github.com/liwei1dao/lego/sys/gin/engine" +) + +type Api_Comp struct { + cbase.ModuleCompBase + options *Options + gin gin.ISys +} + +func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { + err = this.ModuleCompBase.Init(service, module, comp, options) + this.options = options.(*Options) + this.gin, err = gin.NewSys(gin.SetListenPort(this.options.Port)) + this.gin.GET("./test", this.test) + return +} + +func (this *Api_Comp) test(c *engine.Context) { + +} diff --git a/modules/web/module.go b/modules/web/module.go index 51a1efe62..0524d2d72 100644 --- a/modules/web/module.go +++ b/modules/web/module.go @@ -3,7 +3,6 @@ package web import ( "go_dreamfactory/comm" "go_dreamfactory/modules" - "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "github.com/liwei1dao/lego/core" @@ -16,9 +15,9 @@ func NewModule() core.IModule { type Web struct { modules.ModuleBase - options *Options - table *cfg.TbItem - user_comp *User_Comp + options *Options + table *cfg.TbItem + api_comp *Api_Comp } func (this *Web) GetType() core.M_Modules { @@ -37,20 +36,20 @@ func (this *Web) Init(service core.IService, module core.IModule, options core.I func (this *Web) Start() (err error) { err = this.ModuleBase.Start() - var ( - data interface{} - ) - if err = configure.RegisterConfigure("tbitem.json", cfg.NewTbItem); err != nil { - return - } - if data, err = configure.GetConfigure("tbitem.json"); err != nil { - return - } - this.table = data.(*cfg.TbItem) + // var ( + // data interface{} + // ) + // if err = configure.RegisterConfigure("tbitem.json", cfg.NewTbItem); err != nil { + // return + // } + // if data, err = configure.GetConfigure("tbitem.json"); err != nil { + // return + // } + // this.table = data.(*cfg.TbItem) return } func (this *Web) OnInstallComp() { this.ModuleBase.OnInstallComp() - this.user_comp = this.RegisterComp(new(User_Comp)).(*User_Comp) + this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp) } diff --git a/modules/web/user_comp.go b/modules/web/user_comp.go deleted file mode 100644 index 62761271a..000000000 --- a/modules/web/user_comp.go +++ /dev/null @@ -1,29 +0,0 @@ -package web - -import ( - "context" - "go_dreamfactory/comm" - "go_dreamfactory/modules" - "go_dreamfactory/pb" - - "github.com/liwei1dao/lego/core" - "github.com/liwei1dao/lego/sys/log" -) - -type User_Comp struct { - modules.MComp_GateComp -} - -func (this *User_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { - this.MComp_GateComp.Init(service, module, comp, options) - return -} - -func (this *User_Comp) Login(ctx context.Context, session comm.IUserSession, rsp *pb.UserLoginReq) error { - log.Debugf("User_Comp Login: session:%v rsp:%v", session.ToString(), rsp) - session.SendMsg("LogigResp", &pb.UserLoginResp{ - Code: 200, - }) - - return nil -} diff --git a/services/web/main.go b/services/web/main.go new file mode 100644 index 000000000..03e73da3b --- /dev/null +++ b/services/web/main.go @@ -0,0 +1,44 @@ +package main + +import ( + "flag" + "go_dreamfactory/modules/web" + "go_dreamfactory/services" + + "github.com/liwei1dao/lego" + "github.com/liwei1dao/lego/base/rpcx" + "github.com/liwei1dao/lego/core" +) + +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( //装备组件 + services.NewGateRouteComp(), + ) + 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() +}