go_dreamfactory/modules/comp_match.go
2023-10-23 16:41:21 +08:00

62 lines
1.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package modules
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/base"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/core/cbase"
"log"
"reflect"
)
/*
模块 网关组件 接收处理用户传递消息
*/
type MCompMatch struct {
cbase.ModuleCompBase
service base.IRPCXService //rpc服务对象
module core.IModule //当前业务模块
comp core.IModuleComp //网关组件自己
scomp comm.ISC_MatchComp
PoolName string
}
//组件初始化接口
func (this *MCompMatch) 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
}
//组件启动接口启动时将自己接收用户消息的处理函数注册到services/comp_gateroute.go 对象中
func (this *MCompMatch) Start() (err error) {
if err = this.ModuleCompBase.Start(); err != nil {
return
}
var comp core.IServiceComp
//注册远程路由
if comp, err = this.service.GetComp(comm.SC_ServiceMatchComp); err != nil {
return
}
this.scomp = comp.(comm.ISC_MatchComp)
this.suitableMethods()
return
}
//反射注册相关接口道services/comp_gateroute.go 对象中
func (this *MCompMatch) suitableMethods() {
typ := reflect.TypeOf(this.comp)
for m := 0; m < typ.NumMethod(); m++ {
method := typ.Method(m)
mname := method.Name
if mname == "MatchNotic" {
agrType := typ.In(1)
this.scomp.RegisterMatchPool(this.PoolName, reflect.ValueOf(this.comp), agrType, method)
return
}
}
log.Panicf("反射注册匹配池处理函数错误 [%s-%s] Api接口格式错误", this.module.GetType(), "MatchNotic")
}