diff --git a/config/remote/etcd/etcd.go b/config/remote/etcd/etcd.go index 16575e8b..a030dbe0 100644 --- a/config/remote/etcd/etcd.go +++ b/config/remote/etcd/etcd.go @@ -15,11 +15,11 @@ import ( // The remote client uses etcd. type ETCD struct { key string - clientConfig *clientv3.Config + clientConfig clientv3.Config } // Provider create a *ETCD -func Provider(clientConfig *clientv3.Config, key string) *ETCD { +func Provider(clientConfig clientv3.Config, key string) *ETCD { return &ETCD{ key: key, clientConfig: clientConfig, @@ -28,14 +28,14 @@ func Provider(clientConfig *clientv3.Config, key string) *ETCD { // WithKey is a two-in-one coreOption. It uses the remote key on etcd as the // source of configuration, and watches the change of that key for hot reloading. -func WithKey(cfg *clientv3.Config, key string, codec contract.Codec) (core.CoreOption, core.CoreOption) { +func WithKey(cfg clientv3.Config, key string, codec contract.Codec) (core.CoreOption, core.CoreOption) { r := Provider(cfg, key) return core.WithConfigStack(r, config.CodecParser{Codec: codec}), core.WithConfigWatcher(r) } // ReadBytes reads the contents of a key from etcd and returns the bytes. func (r *ETCD) ReadBytes() ([]byte, error) { - client, err := clientv3.New(*r.clientConfig) + client, err := clientv3.New(r.clientConfig) if err != nil { return nil, err } @@ -62,7 +62,7 @@ func (r *ETCD) Read() (map[string]interface{}, error) { // it should reload the whole config stack. For example, if the flag or env takes precedence over the config // key, they should remain to be so after the key changes. func (r *ETCD) Watch(ctx context.Context, reload func() error) error { - client, err := clientv3.New(*r.clientConfig) + client, err := clientv3.New(r.clientConfig) if err != nil { return err } diff --git a/config/remote/etcd/etcd_test.go b/config/remote/etcd/etcd_test.go index 007e84eb..a8a987ff 100644 --- a/config/remote/etcd/etcd_test.go +++ b/config/remote/etcd/etcd_test.go @@ -19,12 +19,12 @@ func TestRemote(t *testing.T) { return } addrs := strings.Split(os.Getenv("ETCD_ADDR"), ",") - cfg := &clientv3.Config{ + cfg := clientv3.Config{ Endpoints: addrs, DialTimeout: 2 * time.Second, } - r := Provider("config.yaml", cfg) + r := Provider(cfg, "config.yaml") var testVal = "name: app" // PREPARE TEST DATA @@ -71,12 +71,12 @@ func TestError(t *testing.T) { err error ) - cfg := &clientv3.Config{ + cfg := clientv3.Config{ Endpoints: []string{}, DialTimeout: 2 * time.Second, } - r = Provider("config.yaml", cfg) + r = Provider(cfg, "config.yaml") err = put(r, "test") assert.Error(t, err) @@ -88,15 +88,15 @@ func TestError(t *testing.T) { }) assert.Error(t, err) - cfg = &clientv3.Config{ + cfg = clientv3.Config{ Endpoints: addrs, DialTimeout: 2 * time.Second, } - r = Provider("config-test1", cfg) + r = Provider(cfg, "config-test1") _, err = r.ReadBytes() assert.Error(t, err) - r = Provider("config-test2", cfg) + r = Provider(cfg, "config-test2") // Confirm that the two coroutines are finished g := sync.WaitGroup{} @@ -127,7 +127,7 @@ func TestError(t *testing.T) { } func put(r *ETCD, val string) error { - client, err := clientv3.New(*r.clientConfig) + client, err := clientv3.New(r.clientConfig) if err != nil { return err } diff --git a/config/remote/etcd/example_test.go b/config/remote/etcd/example_test.go index d05fc3dd..cadc5789 100644 --- a/config/remote/etcd/example_test.go +++ b/config/remote/etcd/example_test.go @@ -20,7 +20,7 @@ func Example() { } key := "core.yaml" envEtcdAddrs := strings.Split(addr, ",") - cfg := &clientv3.Config{ + cfg := clientv3.Config{ Endpoints: envEtcdAddrs, DialTimeout: time.Second, } @@ -34,8 +34,8 @@ func Example() { // etcd } -func put(cfg *clientv3.Config, key, val string) error { - client, err := clientv3.New(*cfg) +func put(cfg clientv3.Config, key, val string) error { + client, err := clientv3.New(cfg) if err != nil { return err }