Skip to content

Commit c0a30ed

Browse files
authored
Merge pull request #2 from deepthawtz/dylan/fix_prefix_bug
fix prefix bug
2 parents 399b8b0 + 8f08dd7 commit c0a30ed

File tree

5 files changed

+12
-10
lines changed

5 files changed

+12
-10
lines changed

cmd/del.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package cmd
1717
import (
1818
"fmt"
1919
"os"
20-
"strings"
20+
"path"
2121
"sync"
2222

2323
"github.com/deepthawtz/kv/store"
@@ -58,7 +58,7 @@ func del(client *consul.KV, args ...string) error {
5858
for _, k := range args {
5959
wg.Add(1)
6060
go func(k string) {
61-
key := strings.Join([]string{prefix, k}, "/")
61+
key := path.Join(prefix, k)
6262
_, err := client.Delete(key, nil)
6363
if err != nil {
6464
panic(err)

cmd/del_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package cmd
22

33
import (
4-
"strings"
4+
"path"
55
"testing"
66

77
consul "github.com/hashicorp/consul/api"
@@ -13,7 +13,7 @@ func TestDel(t *testing.T) {
1313
kv := c.KV()
1414

1515
prefix = "env/yo/stage"
16-
k := strings.Join([]string{prefix, "YO"}, "/")
16+
k := path.Join(prefix, "YO")
1717
_, _ = kv.Put(&consul.KVPair{Key: k, Value: []byte("123")}, nil)
1818

1919
if err := del(kv, []string{"YO"}...); err != nil {

cmd/get.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package cmd
1717
import (
1818
"fmt"
1919
"os"
20+
"path"
2021
"regexp"
2122
"strings"
2223

@@ -136,7 +137,7 @@ func matchingKVPairs(scoped consul.KVPairs, args []string) (consul.KVPairs, erro
136137

137138
for _, s := range specific {
138139
for _, k := range scoped {
139-
key := strings.Join([]string{prefix, s}, "/")
140+
key := path.Join(prefix, s)
140141
if key == string(k.Key) {
141142
kvpairs = append(kvpairs, k)
142143
}

cmd/get_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package cmd
22

33
import (
4-
"strings"
4+
"path"
55
"testing"
66

77
consul "github.com/hashicorp/consul/api"
@@ -40,11 +40,11 @@ func TestGet(t *testing.T) {
4040
kv := c.KV()
4141

4242
prefix = "env/yo/stage"
43-
k := strings.Join([]string{prefix, "YO"}, "/")
43+
k := path.Join(prefix, "YO")
4444
_, _ = kv.Put(&consul.KVPair{Key: k, Value: []byte("123")}, nil)
45-
k = strings.Join([]string{prefix, "THING_ID"}, "/")
45+
k = path.Join(prefix, "THING_ID")
4646
_, _ = kv.Put(&consul.KVPair{Key: k, Value: []byte("abc123")}, nil)
47-
k = strings.Join([]string{prefix, "THING_TOKEN"}, "/")
47+
k = path.Join(prefix, "THING_TOKEN")
4848
_, _ = kv.Put(&consul.KVPair{Key: k, Value: []byte("yabbadabba")}, nil)
4949

5050
cases := []struct {

cmd/set.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package cmd
1717
import (
1818
"fmt"
1919
"os"
20+
"path"
2021
"strings"
2122
"sync"
2223

@@ -73,7 +74,7 @@ func set(client *consul.KV, args ...string) error {
7374

7475
wg.Add(1)
7576
go func() {
76-
k := strings.Join([]string{prefix, parts[0]}, "/")
77+
k := path.Join(prefix, parts[0])
7778
v := parts[1]
7879
fmt.Printf("setting %s = %s\n", k, v)
7980
if _, err := client.Put(&consul.KVPair{Key: k, Value: []byte(v)}, nil); err != nil {

0 commit comments

Comments
 (0)