aboutsummaryrefslogtreecommitdiff
path: root/util.go
diff options
context:
space:
mode:
Diffstat (limited to 'util.go')
-rw-r--r--util.go14
1 files changed, 7 insertions, 7 deletions
diff --git a/util.go b/util.go
index d8ae58e..014805c 100644
--- a/util.go
+++ b/util.go
@@ -3,7 +3,6 @@ package main
import (
"encoding/json"
"fmt"
- "log"
"strings"
consul "github.com/hashicorp/consul/api"
@@ -24,7 +23,7 @@ func dnToConsul(dn string) (string, error) {
return strings.Join(rdns, "/"), nil
}
-func consulToDN(key string) (string, string) {
+func consulToDN(key string) (string, string, error) {
path := strings.Split(key, "/")
dn := ""
for _, cpath := range path {
@@ -33,16 +32,14 @@ func consulToDN(key string) (string, string) {
}
kv := strings.Split(cpath, "=")
if len(kv) == 2 && kv[0] == "attribute" {
- return dn, kv[1]
+ return dn, kv[1], nil
}
if dn != "" {
dn = "," + dn
}
dn = cpath + dn
}
- // TODO don't panic, handle this
- log.Panicf("Consul key %s does not end with attribute=something", key)
- panic("unreachable")
+ return "", "", fmt.Errorf("Consul key %s does not end with attribute=something", key)
}
func parseValue(value []byte) ([]string, error) {
@@ -65,7 +62,10 @@ func parseConsulResult(data []*consul.KVPair) (map[string]Entry, error) {
aggregator := map[string]Entry{}
for _, kv := range data {
- dn, attr := consulToDN(kv.Key)
+ dn, attr, err := consulToDN(kv.Key)
+ if err != nil {
+ continue
+ }
if _, exists := aggregator[dn]; !exists {
aggregator[dn] = Entry{}
}