This commit is contained in:
crusader 2018-04-05 13:02:04 +09:00
parent 23658adc4b
commit 13d627dd6a

View File

@ -17,6 +17,8 @@ type RPCRegistry interface {
RPCInvoker RPCInvoker
GetService(name string) interface{} GetService(name string) interface{}
RegisterService(receiver interface{}, name string) error RegisterService(receiver interface{}, name string) error
RegisterServices(receivers ...interface{}) error
RegisterServiceMap(keysAndValues map[string]interface{}) error
} }
// RPCRegistry serves registered RPC services using registered codecs. // RPCRegistry serves registered RPC services using registered codecs.
@ -44,6 +46,32 @@ func (rr *rpcRegistry) RegisterService(receiver interface{}, name string) error
return rr.services.register(receiver, name) return rr.services.register(receiver, name)
} }
func (rr *rpcRegistry) RegisterServices(receivers ...interface{}) error {
if nil == receivers || 0 == len(receivers) {
return nil
}
for _, receiver := range receivers {
if err := rr.services.register(receiver, ""); nil != err {
return err
}
}
return nil
}
func (rr *rpcRegistry) RegisterServiceMap(keysAndValues map[string]interface{}) error {
if nil == keysAndValues || 0 == len(keysAndValues) {
return nil
}
for name, receiver := range keysAndValues {
if err := rr.services.register(receiver, name); nil != err {
return err
}
}
return nil
}
func (rr *rpcRegistry) GetService(name string) interface{} { func (rr *rpcRegistry) GetService(name string) interface{} {
return rr.services.getService(name) return rr.services.getService(name)
} }