Skip to content

Commit f08aebf

Browse files
committed
feat(nestedArray): integrate wildcard filter in compilePath
1 parent e287bd6 commit f08aebf

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

pkg/customresourcestate/registry_factory.go

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -617,22 +617,23 @@ func compilePath(path []string) (out valuePath, _ error) {
617617
for i := range path {
618618
part := path[i]
619619

620-
if part == "[*]" {
621-
// wildcard: retourner tous les éléments d'un array
622-
out = append(out, pathOp{
623-
part: part,
624-
op: func(m interface{}) interface{} {
625-
if s, ok := m.([]interface{}); ok {
626-
return s
627-
}
628-
return nil
629-
},
630-
})
631-
continue
632-
}
633-
634620
if strings.HasPrefix(part, "[") && strings.HasSuffix(part, "]") {
635621

622+
// Wildcard with filter: [*]
623+
if part == "[*]" {
624+
// function to return all elements in a list
625+
out = append(out, pathOp{
626+
part: part,
627+
op: func(m interface{}) interface{} {
628+
if s, ok := m.([]interface{}); ok {
629+
return s
630+
}
631+
return nil
632+
},
633+
})
634+
continue
635+
}
636+
636637
// list lookup: [key=value]
637638
eq := strings.SplitN(part[1:len(part)-1], "=", 2)
638639
if len(eq) != 2 {
@@ -677,9 +678,7 @@ func compilePath(path []string) (out valuePath, _ error) {
677678
} else {
678679
out = append(out, pathOp{
679680
part: part,
680-
// Function qui sera utilisé dans le Get pour descendre dans l'arborescence (op.op(obj))
681681
op: func(m interface{}) interface{} {
682-
// On cherche du clé valeur dans une map
683682
if mp, ok := m.(map[string]interface{}); ok {
684683
kv := strings.Split(part, "=")
685684
if len(kv) == 2 /* k=v */ {
@@ -692,8 +691,6 @@ func compilePath(path []string) (out valuePath, _ error) {
692691
}
693692
}
694693
return mp[part]
695-
// On va checher un index dans une liste
696-
// ex: [0], [1], ... -> on pourrait ici faire le boulot si *
697694
} else if s, ok := m.([]interface{}); ok {
698695
i, err := strconv.Atoi(part)
699696
if err != nil {

0 commit comments

Comments
 (0)