优化用户路由祖册接口

This commit is contained in:
liwei1dao 2022-06-01 17:41:48 +08:00
parent 02f6e13e25
commit aeb1a1ab4d
6 changed files with 92 additions and 48 deletions

View File

@ -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

View File

@ -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)
}
}

26
modules/web/api_comp.go Normal file
View File

@ -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) {
}

View File

@ -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)
}

View File

@ -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
}

44
services/web/main.go Normal file
View File

@ -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()
}