优化初始化方式

This commit is contained in:
duanhf2012
2020-03-28 11:06:22 +08:00
parent 0ddeceb977
commit 7745ed39f3
7 changed files with 17 additions and 8 deletions

View File

@@ -16,6 +16,7 @@ type IService interface {
Init(iservice IService,getClientFun rpc.FuncRpcClient,getServerFun rpc.FuncRpcServer,serviceCfg interface{})
GetName() string
OnSetup(iservice IService)
OnInit() error
OnRelease()
Wait()
@@ -38,8 +39,14 @@ type Service struct {
startStatus bool
}
func (slf *Service) OnSetup(iservice IService){
if iservice.GetName() == "" {
slf.name = reflect.Indirect(reflect.ValueOf(iservice)).Type().Name()
}
}
func (slf *Service) Init(iservice IService,getClientFun rpc.FuncRpcClient,getServerFun rpc.FuncRpcServer,serviceCfg interface{}) {
slf.name = reflect.Indirect(reflect.ValueOf(iservice)).Type().Name()
slf.dispatcher =timer.NewDispatcher(timerDispatcherLen)
slf.this = iservice
slf.InitRpcHandler(iservice.(rpc.IRpcHandler),getClientFun,getServerFun)