Skip to content

Commit

Permalink
fix: eliminate pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
Reasno committed Aug 6, 2021
1 parent d16c9e5 commit 2c198be
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
10 changes: 5 additions & 5 deletions config/remote/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
16 changes: 8 additions & 8 deletions config/remote/etcd/etcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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{}
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions config/remote/etcd/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func Example() {
}
key := "core.yaml"
envEtcdAddrs := strings.Split(addr, ",")
cfg := &clientv3.Config{
cfg := clientv3.Config{
Endpoints: envEtcdAddrs,
DialTimeout: time.Second,
}
Expand All @@ -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
}
Expand Down

0 comments on commit 2c198be

Please sign in to comment.