clientv3: hide retry dial api
parent
7709cd84bb
commit
22744566f4
|
@ -76,8 +76,8 @@ type Client struct {
|
||||||
|
|
||||||
// New creates a new etcdv3 client from a given configuration.
|
// New creates a new etcdv3 client from a given configuration.
|
||||||
func New(cfg Config) (*Client, error) {
|
func New(cfg Config) (*Client, error) {
|
||||||
if cfg.RetryDialer == nil {
|
if cfg.retryDialer == nil {
|
||||||
cfg.RetryDialer = dialEndpointList
|
cfg.retryDialer = dialEndpointList
|
||||||
}
|
}
|
||||||
if len(cfg.Endpoints) == 0 {
|
if len(cfg.Endpoints) == 0 {
|
||||||
return nil, ErrNoAvailableEndpoints
|
return nil, ErrNoAvailableEndpoints
|
||||||
|
@ -227,7 +227,7 @@ func WithRequireLeader(ctx context.Context) context.Context {
|
||||||
|
|
||||||
func newClient(cfg *Config) (*Client, error) {
|
func newClient(cfg *Config) (*Client, error) {
|
||||||
if cfg == nil {
|
if cfg == nil {
|
||||||
cfg = &Config{RetryDialer: dialEndpointList}
|
cfg = &Config{retryDialer: dialEndpointList}
|
||||||
}
|
}
|
||||||
var creds *credentials.TransportAuthenticator
|
var creds *credentials.TransportAuthenticator
|
||||||
if cfg.TLS != nil {
|
if cfg.TLS != nil {
|
||||||
|
@ -237,7 +237,7 @@ func newClient(cfg *Config) (*Client, error) {
|
||||||
|
|
||||||
// use a temporary skeleton client to bootstrap first connection
|
// use a temporary skeleton client to bootstrap first connection
|
||||||
ctx, cancel := context.WithCancel(context.TODO())
|
ctx, cancel := context.WithCancel(context.TODO())
|
||||||
conn, err := cfg.RetryDialer(&Client{cfg: *cfg, creds: creds, ctx: ctx, Username: cfg.Username, Password: cfg.Password})
|
conn, err := cfg.retryDialer(&Client{cfg: *cfg, creds: creds, ctx: ctx, Username: cfg.Username, Password: cfg.Password})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -301,7 +301,7 @@ func (c *Client) retryConnection(err error) (newConn *grpc.ClientConn, dialErr e
|
||||||
return nil, c.ctx.Err()
|
return nil, c.ctx.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
c.conn, dialErr = c.cfg.RetryDialer(c)
|
c.conn, dialErr = c.cfg.retryDialer(c)
|
||||||
if dialErr != nil {
|
if dialErr != nil {
|
||||||
c.errors = append(c.errors, dialErr)
|
c.errors = append(c.errors, dialErr)
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,8 +32,9 @@ type Config struct {
|
||||||
// Endpoints is a list of URLs
|
// Endpoints is a list of URLs
|
||||||
Endpoints []string
|
Endpoints []string
|
||||||
|
|
||||||
// RetryDialer chooses the next endpoint to use
|
// retryDialer chooses the next endpoint to use
|
||||||
RetryDialer EndpointDialer
|
// keep private until the grpc rebalancer is sorted out
|
||||||
|
retryDialer EndpointDialer
|
||||||
|
|
||||||
// DialTimeout is the timeout for failing to establish a connection.
|
// DialTimeout is the timeout for failing to establish a connection.
|
||||||
DialTimeout time.Duration
|
DialTimeout time.Duration
|
||||||
|
|
Loading…
Reference in New Issue