aboutsummaryrefslogtreecommitdiff
path: root/model/query.go
diff options
context:
space:
mode:
Diffstat (limited to 'model/query.go')
-rw-r--r--model/query.go14
1 files changed, 7 insertions, 7 deletions
diff --git a/model/query.go b/model/query.go
index 75ee6b0..56a0dfe 100644
--- a/model/query.go
+++ b/model/query.go
@@ -6,13 +6,13 @@ import (
)
// Query returns node by array query
-func (n *Node) Query(query []string) (*Node, error) {
+func Query(n Node, query []string) (Node, error) {
if len(query) == 0 {
return n, nil
}
head, rest := query[0], query[1:]
- switch n.Type {
- case ArrayNode:
+ switch n := n.(type) {
+ case *ArrayNode:
idx, err := strconv.Atoi(head)
if err != nil {
return nil, fmt.Errorf("index must be a number, got %s", head)
@@ -21,13 +21,13 @@ func (n *Node) Query(query []string) (*Node, error) {
if err != nil {
return nil, err
}
- return next.Query(rest)
- case ObjectNode:
+ return Query(next, rest)
+ case *ObjectNode:
next, err := n.Get(head)
if err != nil {
return nil, err
}
- return next.Query(rest)
+ return Query(next, rest)
}
- return nil, fmt.Errorf("can't get %s from node type %s", head, n.Type)
+ return nil, fmt.Errorf("can't get %s from node type %s", head, n.Type())
}