Browse Source

Merge pull request #4383 from xiang90/client_no_end

clientv3: add no endpoint error
Xiang Li 10 years ago
parent
commit
5f9f56ca17
1 changed files with 9 additions and 0 deletions
  1. 9 0
      clientv3/client.go

+ 9 - 0
clientv3/client.go

@@ -15,6 +15,7 @@
 package clientv3
 
 import (
+	"errors"
 	"net"
 	"net/url"
 	"sync"
@@ -27,6 +28,10 @@ import (
 	"github.com/coreos/etcd/pkg/transport"
 )
 
+var (
+	ErrNoAvailableEndpoints = errors.New("etcdclient: no available endpoints")
+)
+
 // Client provides and manages an etcd v3 client session.
 type Client struct {
 	// KV is the keyvalue API for the client's connection.
@@ -67,6 +72,10 @@ func New(cfg Config) (*Client, error) {
 	if cfg.RetryDialer == nil {
 		cfg.RetryDialer = dialEndpointList
 	}
+	if len(cfg.Endpoints) == 0 {
+		return nil, ErrNoAvailableEndpoints
+	}
+
 	return newClient(&cfg)
 }