use a totally different client for the watcher in etcd
This commit is contained in:
		| @@ -51,13 +51,10 @@ func NewRegistry(opts ...registry.Option) registry.Registry { | ||||
| 	return e | ||||
| } | ||||
|  | ||||
| func configure(e *etcdRegistry, opts ...registry.Option) error { | ||||
| func newClient(e *etcdRegistry) (*clientv3.Client, error) { | ||||
| 	config := clientv3.Config{ | ||||
| 		Endpoints: []string{"127.0.0.1:2379"}, | ||||
| 	} | ||||
| 	for _, o := range opts { | ||||
| 		o(&e.options) | ||||
| 	} | ||||
|  | ||||
| 	if e.options.Timeout == 0 { | ||||
| 		e.options.Timeout = 5 * time.Second | ||||
| @@ -117,17 +114,32 @@ func configure(e *etcdRegistry, opts ...registry.Option) error { | ||||
| 	} | ||||
|  | ||||
| 	cli, err := clientv3.New(config) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	return cli, nil | ||||
| } | ||||
|  | ||||
| // configure will setup the registry with new options | ||||
| func configure(e *etcdRegistry, opts ...registry.Option) error { | ||||
| 	for _, o := range opts { | ||||
| 		o(&e.options) | ||||
| 	} | ||||
|  | ||||
| 	// setup the client | ||||
| 	cli, err := newClient(e) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	// close the existing client | ||||
| 	if e.client != nil { | ||||
| 		e.client.Close() | ||||
| 	} | ||||
|  | ||||
| 	// set the new client | ||||
| 	// setup new client | ||||
| 	e.client = cli | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| @@ -566,7 +578,11 @@ func (e *etcdRegistry) ListServices(opts ...registry.ListOption) ([]*registry.Se | ||||
| } | ||||
|  | ||||
| func (e *etcdRegistry) Watch(opts ...registry.WatchOption) (registry.Watcher, error) { | ||||
| 	return newEtcdWatcher(e, e.options.Timeout, opts...) | ||||
| 	cli, err := newClient(e) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	return newEtcdWatcher(cli, e.options.Timeout, opts...) | ||||
| } | ||||
|  | ||||
| func (e *etcdRegistry) String() string { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user