优化用户路由祖册接口
This commit is contained in:
parent
02f6e13e25
commit
aeb1a1ab4d
@ -12,9 +12,9 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SM_GateModule core.M_Modules = "SM_GateModule" //gate模块 网关服务模块
|
SM_GateModule core.M_Modules = "gateway" //gate模块 网关服务模块
|
||||||
SM_WebModule core.M_Modules = "SM_WebModule" //web模块
|
SM_WebModule core.M_Modules = "web" //web模块
|
||||||
SM_LoginModule core.M_Modules = "SM_LoginModule" //web模块
|
SM_LoginModule core.M_Modules = "login" //web模块
|
||||||
)
|
)
|
||||||
|
|
||||||
const ( //Rpc
|
const ( //Rpc
|
||||||
|
@ -2,8 +2,10 @@ package modules
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"go_dreamfactory/comm"
|
"go_dreamfactory/comm"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
@ -22,12 +24,14 @@ var typeOfError = reflect.TypeOf((*error)(nil)).Elem()
|
|||||||
type MComp_GateComp struct {
|
type MComp_GateComp struct {
|
||||||
cbase.ModuleCompBase
|
cbase.ModuleCompBase
|
||||||
service base.IRPCXService
|
service base.IRPCXService
|
||||||
|
module core.IModule
|
||||||
comp core.IModuleComp
|
comp core.IModuleComp
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *MComp_GateComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
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.ModuleCompBase.Init(service, module, comp, options)
|
||||||
this.service = service.(base.IRPCXService)
|
this.service = service.(base.IRPCXService)
|
||||||
|
this.module = module
|
||||||
this.comp = comp
|
this.comp = comp
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -86,7 +90,7 @@ func (this *MComp_GateComp) suitableMethods(scomp comm.ISC_GateRouteComp, typ re
|
|||||||
if returnType := mtype.Out(0); returnType != typeOfError {
|
if returnType := mtype.Out(0); returnType != typeOfError {
|
||||||
continue
|
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
26
modules/web/api_comp.go
Normal 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) {
|
||||||
|
|
||||||
|
}
|
@ -3,7 +3,6 @@ package web
|
|||||||
import (
|
import (
|
||||||
"go_dreamfactory/comm"
|
"go_dreamfactory/comm"
|
||||||
"go_dreamfactory/modules"
|
"go_dreamfactory/modules"
|
||||||
"go_dreamfactory/sys/configure"
|
|
||||||
cfg "go_dreamfactory/sys/configure/structs"
|
cfg "go_dreamfactory/sys/configure/structs"
|
||||||
|
|
||||||
"github.com/liwei1dao/lego/core"
|
"github.com/liwei1dao/lego/core"
|
||||||
@ -18,7 +17,7 @@ type Web struct {
|
|||||||
modules.ModuleBase
|
modules.ModuleBase
|
||||||
options *Options
|
options *Options
|
||||||
table *cfg.TbItem
|
table *cfg.TbItem
|
||||||
user_comp *User_Comp
|
api_comp *Api_Comp
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Web) GetType() core.M_Modules {
|
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) {
|
func (this *Web) Start() (err error) {
|
||||||
err = this.ModuleBase.Start()
|
err = this.ModuleBase.Start()
|
||||||
var (
|
// var (
|
||||||
data interface{}
|
// data interface{}
|
||||||
)
|
// )
|
||||||
if err = configure.RegisterConfigure("tbitem.json", cfg.NewTbItem); err != nil {
|
// if err = configure.RegisterConfigure("tbitem.json", cfg.NewTbItem); err != nil {
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
if data, err = configure.GetConfigure("tbitem.json"); err != nil {
|
// if data, err = configure.GetConfigure("tbitem.json"); err != nil {
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
this.table = data.(*cfg.TbItem)
|
// this.table = data.(*cfg.TbItem)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Web) OnInstallComp() {
|
func (this *Web) OnInstallComp() {
|
||||||
this.ModuleBase.OnInstallComp()
|
this.ModuleBase.OnInstallComp()
|
||||||
this.user_comp = this.RegisterComp(new(User_Comp)).(*User_Comp)
|
this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp)
|
||||||
}
|
}
|
||||||
|
@ -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
44
services/web/main.go
Normal 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()
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user