From 76a7f461ebbde70ea0e3d4f9b79c08139acaee7c Mon Sep 17 00:00:00 2001 From: NeonXP Date: Tue, 27 Dec 2022 02:37:02 +0300 Subject: Completely rewrited --- model/query.go | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 model/query.go (limited to 'model/query.go') diff --git a/model/query.go b/model/query.go deleted file mode 100644 index 56a0dfe..0000000 --- a/model/query.go +++ /dev/null @@ -1,33 +0,0 @@ -package model - -import ( - "fmt" - "strconv" -) - -// Query returns node by array query -func Query(n Node, query []string) (Node, error) { - if len(query) == 0 { - return n, nil - } - head, rest := query[0], query[1:] - 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) - } - next, err := n.Index(idx) - if err != nil { - return nil, err - } - return Query(next, rest) - case *ObjectNode: - next, err := n.Get(head) - if err != nil { - return nil, err - } - return Query(next, rest) - } - return nil, fmt.Errorf("can't get %s from node type %s", head, n.Type()) -} -- cgit v1.2.3