aboutsummaryrefslogtreecommitdiff
path: root/model/query.go
diff options
context:
space:
mode:
authorNeonXP <i@neonxp.dev>2022-12-27 02:37:02 +0300
committerNeonXP <i@neonxp.dev>2022-12-27 02:40:03 +0300
commit76a7f461ebbde70ea0e3d4f9b79c08139acaee7c (patch)
tree5e6dcb05f00be5109b3465ef16a6e9169a27497e /model/query.go
parent6f1d1df79f161cfc695f74d271d689ba72c44d09 (diff)
Completely rewritedv0.1.0
Diffstat (limited to 'model/query.go')
-rw-r--r--model/query.go33
1 files changed, 0 insertions, 33 deletions
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())
-}