1
0
Fork 0

Allows multi-level KV prefixes

This commit is contained in:
Никита Тимофеев 2020-08-11 18:42:05 +03:00 committed by GitHub
parent de458b7357
commit 449afea4fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 89 additions and 38 deletions

View file

@ -20,13 +20,13 @@ func DecodeToNode(pairs []*store.KVPair, rootName string, filters ...string) (*p
var node *parser.Node
for i, pair := range sortedPairs {
split := strings.FieldsFunc(pair.Key, func(c rune) bool { return c == '/' })
if split[0] != rootName {
return nil, fmt.Errorf("invalid label root %s", split[0])
if !strings.HasPrefix(pair.Key, rootName+"/") {
return nil, fmt.Errorf("invalid label root %s", rootName)
}
var parts []string
split := strings.Split(pair.Key[len(rootName)+1:], "/")
parts := []string{rootName}
for _, fragment := range split {
if exp.MatchString(fragment) {
parts = append(parts, "["+fragment+"]")