@@ -3,65 +3,59 @@ package api
3
3
import (
4
4
"strconv"
5
5
6
- "github.com/jmespath-community/go-jmespath/pkg/functions"
7
6
"github.com/jmespath-community/go-jmespath/pkg/interpreter"
8
7
"github.com/jmespath-community/go-jmespath/pkg/parsing"
9
8
)
10
9
11
10
// JMESPath is the representation of a compiled JMES path query. A JMESPath is
12
11
// safe for concurrent use by multiple goroutines.
13
12
type JMESPath interface {
14
- Search (interface {}) (interface {}, error )
13
+ Search (interface {}, ... interpreter. Option ) (interface {}, error )
15
14
}
16
15
17
16
type jmesPath struct {
18
- node parsing.ASTNode
19
- caller interpreter.FunctionCaller
17
+ node parsing.ASTNode
20
18
}
21
19
22
- func newJMESPath (node parsing.ASTNode , funcs ... functions. FunctionEntry ) JMESPath {
20
+ func newJMESPath (node parsing.ASTNode ) JMESPath {
23
21
return jmesPath {
24
- node : node ,
25
- caller : interpreter .NewFunctionCaller (funcs ... ),
22
+ node : node ,
26
23
}
27
24
}
28
25
29
26
// Compile parses a JMESPath expression and returns, if successful, a JMESPath
30
27
// object that can be used to match against data.
31
- func Compile (expression string , funcs ... functions. FunctionEntry ) (JMESPath , error ) {
28
+ func Compile (expression string ) (JMESPath , error ) {
32
29
parser := parsing .NewParser ()
33
30
ast , err := parser .Parse (expression )
34
31
if err != nil {
35
32
return nil , err
36
33
}
37
- var f []functions.FunctionEntry
38
- f = append (f , functions .GetDefaultFunctions ()... )
39
- f = append (f , funcs ... )
40
- return newJMESPath (ast , f ... ), nil
34
+ return newJMESPath (ast ), nil
41
35
}
42
36
43
37
// MustCompile is like Compile but panics if the expression cannot be parsed.
44
38
// It simplifies safe initialization of global variables holding compiled
45
39
// JMESPaths.
46
- func MustCompile (expression string , funcs ... functions. FunctionEntry ) JMESPath {
47
- jmespath , err := Compile (expression , funcs ... )
40
+ func MustCompile (expression string ) JMESPath {
41
+ jmespath , err := Compile (expression )
48
42
if err != nil {
49
43
panic (`jmespath: Compile(` + strconv .Quote (expression ) + `): ` + err .Error ())
50
44
}
51
45
return jmespath
52
46
}
53
47
54
48
// Search evaluates a JMESPath expression against input data and returns the result.
55
- func (jp jmesPath ) Search (data interface {}) (interface {}, error ) {
56
- intr := interpreter .NewInterpreter (data , jp . caller , nil )
57
- return intr .Execute (jp .node , data )
49
+ func (jp jmesPath ) Search (data interface {}, opts ... interpreter. Option ) (interface {}, error ) {
50
+ intr := interpreter .NewInterpreter (data , nil )
51
+ return intr .Execute (jp .node , data , opts ... )
58
52
}
59
53
60
54
// Search evaluates a JMESPath expression against input data and returns the result.
61
- func Search (expression string , data interface {}, funcs ... functions. FunctionEntry ) (interface {}, error ) {
62
- compiled , err := Compile (expression , funcs ... )
55
+ func Search (expression string , data interface {}, opts ... interpreter. Option ) (interface {}, error ) {
56
+ compiled , err := Compile (expression )
63
57
if err != nil {
64
58
return nil , err
65
59
}
66
- return compiled .Search (data )
60
+ return compiled .Search (data , opts ... )
67
61
}
0 commit comments