aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/jmespath/go-jmespath/api.go
diff options
context:
space:
mode:
authorJake Champlin <jake.champlin.27@gmail.com>2017-06-06 12:40:07 -0400
committerJake Champlin <jake.champlin.27@gmail.com>2017-06-06 12:40:07 -0400
commitbae9f6d2fd5eb5bc80929bd393932b23f14d7c93 (patch)
treeca9ab12a7d78b1fc27a8f734729081357ce6d252 /vendor/github.com/jmespath/go-jmespath/api.go
parent254c495b6bebab3fb72a243c4bce858d79e6ee99 (diff)
downloadterraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.tar.gz
terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.tar.zst
terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.zip
Initial transfer of provider code
Diffstat (limited to 'vendor/github.com/jmespath/go-jmespath/api.go')
-rw-r--r--vendor/github.com/jmespath/go-jmespath/api.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/vendor/github.com/jmespath/go-jmespath/api.go b/vendor/github.com/jmespath/go-jmespath/api.go
new file mode 100644
index 0000000..9cfa988
--- /dev/null
+++ b/vendor/github.com/jmespath/go-jmespath/api.go
@@ -0,0 +1,49 @@
1package jmespath
2
3import "strconv"
4
5// JmesPath is the epresentation of a compiled JMES path query. A JmesPath is
6// safe for concurrent use by multiple goroutines.
7type JMESPath struct {
8 ast ASTNode
9 intr *treeInterpreter
10}
11
12// Compile parses a JMESPath expression and returns, if successful, a JMESPath
13// object that can be used to match against data.
14func Compile(expression string) (*JMESPath, error) {
15 parser := NewParser()
16 ast, err := parser.Parse(expression)
17 if err != nil {
18 return nil, err
19 }
20 jmespath := &JMESPath{ast: ast, intr: newInterpreter()}
21 return jmespath, nil
22}
23
24// MustCompile is like Compile but panics if the expression cannot be parsed.
25// It simplifies safe initialization of global variables holding compiled
26// JMESPaths.
27func MustCompile(expression string) *JMESPath {
28 jmespath, err := Compile(expression)
29 if err != nil {
30 panic(`jmespath: Compile(` + strconv.Quote(expression) + `): ` + err.Error())
31 }
32 return jmespath
33}
34
35// Search evaluates a JMESPath expression against input data and returns the result.
36func (jp *JMESPath) Search(data interface{}) (interface{}, error) {
37 return jp.intr.Execute(jp.ast, data)
38}
39
40// Search evaluates a JMESPath expression against input data and returns the result.
41func Search(expression string, data interface{}) (interface{}, error) {
42 intr := newInterpreter()
43 parser := NewParser()
44 ast, err := parser.Parse(expression)
45 if err != nil {
46 return nil, err
47 }
48 return intr.Execute(ast, data)
49}