ing
This commit is contained in:
parent
6250239174
commit
a32e442360
|
@ -59,7 +59,7 @@ type serviceMap struct {
|
|||
}
|
||||
|
||||
// register adds a new service using reflection to extract its methods.
|
||||
func (m *serviceMap) register(rcvr interface{}, name string) error {
|
||||
func (sm *serviceMap) register(rcvr interface{}, name string) error {
|
||||
// Setup service.
|
||||
s := &service{
|
||||
name: name,
|
||||
|
@ -139,14 +139,14 @@ Loop:
|
|||
return fmt.Errorf("rpc: %q has no exported methods of suitable type", s.name)
|
||||
}
|
||||
// Add to the map.
|
||||
m.mutex.Lock()
|
||||
defer m.mutex.Unlock()
|
||||
if m.services == nil {
|
||||
m.services = make(map[string]*service)
|
||||
} else if _, ok := m.services[s.name]; ok {
|
||||
sm.mutex.Lock()
|
||||
defer sm.mutex.Unlock()
|
||||
if sm.services == nil {
|
||||
sm.services = make(map[string]*service)
|
||||
} else if _, ok := sm.services[s.name]; ok {
|
||||
return fmt.Errorf("rpc: service already defined: %q", s.name)
|
||||
}
|
||||
m.services[s.name] = s
|
||||
sm.services[s.name] = s
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -170,15 +170,15 @@ func validateType(t reflect.Type) (rt reflect.Type, rv reflect.Value, err error)
|
|||
// get returns a registered service given a method name.
|
||||
//
|
||||
// The method name uses a dotted notation as in "Service.Method".
|
||||
func (m *serviceMap) get(method string) (*service, *serviceMethod, error) {
|
||||
func (sm *serviceMap) get(method string) (*service, *serviceMethod, error) {
|
||||
parts := strings.Split(method, ".")
|
||||
if len(parts) != 2 {
|
||||
err := fmt.Errorf("rpc: service/method request ill-formed: %q", method)
|
||||
return nil, nil, err
|
||||
}
|
||||
m.mutex.Lock()
|
||||
service := m.services[parts[0]]
|
||||
m.mutex.Unlock()
|
||||
sm.mutex.Lock()
|
||||
service := sm.services[parts[0]]
|
||||
sm.mutex.Unlock()
|
||||
if service == nil {
|
||||
err := fmt.Errorf("rpc: can't find service %q", method)
|
||||
return nil, nil, err
|
||||
|
|
Loading…
Reference in New Issue
Block a user