1. use github.com/coreos instead of go.etcd.io in etcd related import path; 2. add dialtimeout to etcd client
This commit is contained in:
@@ -2,6 +2,7 @@ package etcd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/micro/go-micro/config/source"
|
||||
)
|
||||
@@ -10,13 +11,14 @@ type addressKey struct{}
|
||||
type prefixKey struct{}
|
||||
type stripPrefixKey struct{}
|
||||
type authKey struct{}
|
||||
type dialTimeoutKey struct{}
|
||||
|
||||
type authCreds struct {
|
||||
Username string
|
||||
Password string
|
||||
}
|
||||
|
||||
// WithAddress sets the consul address
|
||||
// WithAddress sets the etcd address
|
||||
func WithAddress(a ...string) source.Option {
|
||||
return func(o *source.Options) {
|
||||
if o.Context == nil {
|
||||
@@ -56,3 +58,13 @@ func Auth(username, password string) source.Option {
|
||||
o.Context = context.WithValue(o.Context, authKey{}, &authCreds{Username: username, Password: password})
|
||||
}
|
||||
}
|
||||
|
||||
// WithDialTimeout set the time out for dialing to etcd
|
||||
func WithDialTimeout(timeout time.Duration) source.Option {
|
||||
return func(o *source.Options) {
|
||||
if o.Context == nil {
|
||||
o.Context = context.Background()
|
||||
}
|
||||
o.Context = context.WithValue(o.Context, dialTimeoutKey{}, timeout)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user