rpc: clean up check for missing methods/subscriptions on handler (#17145)

pull/15691/merge
Wenbiao Zheng 6 years ago committed by Felix Lange
parent fe6a9473dc
commit 68da9aa716
  1. 13
      rpc/server.go

@ -94,11 +94,12 @@ func (s *Server) RegisterName(name string, rcvr interface{}) error {
methods, subscriptions := suitableCallbacks(rcvrVal, svc.typ) methods, subscriptions := suitableCallbacks(rcvrVal, svc.typ)
// already a previous service register under given sname, merge methods/subscriptions if len(methods) == 0 && len(subscriptions) == 0 {
return fmt.Errorf("Service %T doesn't have any suitable methods/subscriptions to expose", rcvr)
}
// already a previous service register under given name, merge methods/subscriptions
if regsvc, present := s.services[name]; present { if regsvc, present := s.services[name]; present {
if len(methods) == 0 && len(subscriptions) == 0 {
return fmt.Errorf("Service %T doesn't have any suitable methods/subscriptions to expose", rcvr)
}
for _, m := range methods { for _, m := range methods {
regsvc.callbacks[formatName(m.method.Name)] = m regsvc.callbacks[formatName(m.method.Name)] = m
} }
@ -111,10 +112,6 @@ func (s *Server) RegisterName(name string, rcvr interface{}) error {
svc.name = name svc.name = name
svc.callbacks, svc.subscriptions = methods, subscriptions svc.callbacks, svc.subscriptions = methods, subscriptions
if len(svc.callbacks) == 0 && len(svc.subscriptions) == 0 {
return fmt.Errorf("Service %T doesn't have any suitable methods/subscriptions to expose", rcvr)
}
s.services[svc.name] = svc s.services[svc.name] = svc
return nil return nil
} }

Loading…
Cancel
Save