diff --git a/cmd/del.go b/cmd/del.go index da8e8cd..190b409 100644 --- a/cmd/del.go +++ b/cmd/del.go @@ -17,7 +17,7 @@ package cmd import ( "fmt" "os" - "strings" + "path" "sync" "github.com/deepthawtz/kv/store" @@ -58,7 +58,7 @@ func del(client *consul.KV, args ...string) error { for _, k := range args { wg.Add(1) go func(k string) { - key := strings.Join([]string{prefix, k}, "/") + key := path.Join(prefix, k) _, err := client.Delete(key, nil) if err != nil { panic(err) diff --git a/cmd/del_test.go b/cmd/del_test.go index 0e567f6..840d9db 100644 --- a/cmd/del_test.go +++ b/cmd/del_test.go @@ -1,7 +1,7 @@ package cmd import ( - "strings" + "path" "testing" consul "github.com/hashicorp/consul/api" @@ -13,7 +13,7 @@ func TestDel(t *testing.T) { kv := c.KV() prefix = "env/yo/stage" - k := strings.Join([]string{prefix, "YO"}, "/") + k := path.Join(prefix, "YO") _, _ = kv.Put(&consul.KVPair{Key: k, Value: []byte("123")}, nil) if err := del(kv, []string{"YO"}...); err != nil { diff --git a/cmd/get.go b/cmd/get.go index c5668b1..a229256 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -17,6 +17,7 @@ package cmd import ( "fmt" "os" + "path" "regexp" "strings" @@ -136,7 +137,7 @@ func matchingKVPairs(scoped consul.KVPairs, args []string) (consul.KVPairs, erro for _, s := range specific { for _, k := range scoped { - key := strings.Join([]string{prefix, s}, "/") + key := path.Join(prefix, s) if key == string(k.Key) { kvpairs = append(kvpairs, k) } diff --git a/cmd/get_test.go b/cmd/get_test.go index 6d5a961..5d7c010 100644 --- a/cmd/get_test.go +++ b/cmd/get_test.go @@ -1,7 +1,7 @@ package cmd import ( - "strings" + "path" "testing" consul "github.com/hashicorp/consul/api" @@ -40,11 +40,11 @@ func TestGet(t *testing.T) { kv := c.KV() prefix = "env/yo/stage" - k := strings.Join([]string{prefix, "YO"}, "/") + k := path.Join(prefix, "YO") _, _ = kv.Put(&consul.KVPair{Key: k, Value: []byte("123")}, nil) - k = strings.Join([]string{prefix, "THING_ID"}, "/") + k = path.Join(prefix, "THING_ID") _, _ = kv.Put(&consul.KVPair{Key: k, Value: []byte("abc123")}, nil) - k = strings.Join([]string{prefix, "THING_TOKEN"}, "/") + k = path.Join(prefix, "THING_TOKEN") _, _ = kv.Put(&consul.KVPair{Key: k, Value: []byte("yabbadabba")}, nil) cases := []struct { diff --git a/cmd/set.go b/cmd/set.go index 3b85111..9b9d643 100644 --- a/cmd/set.go +++ b/cmd/set.go @@ -17,6 +17,7 @@ package cmd import ( "fmt" "os" + "path" "strings" "sync" @@ -73,7 +74,7 @@ func set(client *consul.KV, args ...string) error { wg.Add(1) go func() { - k := strings.Join([]string{prefix, parts[0]}, "/") + k := path.Join(prefix, parts[0]) v := parts[1] fmt.Printf("setting %s = %s\n", k, v) if _, err := client.Put(&consul.KVPair{Key: k, Value: []byte(v)}, nil); err != nil {