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.
|
// 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.
|
// Setup service.
|
||||||
s := &service{
|
s := &service{
|
||||||
name: name,
|
name: name,
|
||||||
|
@ -139,14 +139,14 @@ Loop:
|
||||||
return fmt.Errorf("rpc: %q has no exported methods of suitable type", s.name)
|
return fmt.Errorf("rpc: %q has no exported methods of suitable type", s.name)
|
||||||
}
|
}
|
||||||
// Add to the map.
|
// Add to the map.
|
||||||
m.mutex.Lock()
|
sm.mutex.Lock()
|
||||||
defer m.mutex.Unlock()
|
defer sm.mutex.Unlock()
|
||||||
if m.services == nil {
|
if sm.services == nil {
|
||||||
m.services = make(map[string]*service)
|
sm.services = make(map[string]*service)
|
||||||
} else if _, ok := m.services[s.name]; ok {
|
} else if _, ok := sm.services[s.name]; ok {
|
||||||
return fmt.Errorf("rpc: service already defined: %q", s.name)
|
return fmt.Errorf("rpc: service already defined: %q", s.name)
|
||||||
}
|
}
|
||||||
m.services[s.name] = s
|
sm.services[s.name] = s
|
||||||
return nil
|
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.
|
// get returns a registered service given a method name.
|
||||||
//
|
//
|
||||||
// The method name uses a dotted notation as in "Service.Method".
|
// 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, ".")
|
parts := strings.Split(method, ".")
|
||||||
if len(parts) != 2 {
|
if len(parts) != 2 {
|
||||||
err := fmt.Errorf("rpc: service/method request ill-formed: %q", method)
|
err := fmt.Errorf("rpc: service/method request ill-formed: %q", method)
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
m.mutex.Lock()
|
sm.mutex.Lock()
|
||||||
service := m.services[parts[0]]
|
service := sm.services[parts[0]]
|
||||||
m.mutex.Unlock()
|
sm.mutex.Unlock()
|
||||||
if service == nil {
|
if service == nil {
|
||||||
err := fmt.Errorf("rpc: can't find service %q", method)
|
err := fmt.Errorf("rpc: can't find service %q", method)
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
|
Loading…
Reference in New Issue
Block a user