-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.go
41 lines (35 loc) · 1.08 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package jsonpath
import (
"github.com/evilmonkeyinc/jsonpath/option"
"github.com/evilmonkeyinc/jsonpath/script"
)
// OptionFunction function that can be used as a compile or query option
type OptionFunction func(selector *Selector) error
// Apply the option to the Selector
func (fn OptionFunction) Apply(selector *Selector) error {
return fn(selector)
}
// Option allows to set compile and query options when calling Compile
type Option interface {
// Apply the option to the Selector
Apply(selector *Selector) error
}
// ScriptEngine allows you to set a custom script Engine for the JSONPath selector
func ScriptEngine(engine script.Engine) Option {
return OptionFunction(func(selector *Selector) error {
if selector.engine == nil {
selector.engine = engine
}
return nil
})
}
// QueryOptions allows you to set the query options for the JSONPath selector
func QueryOptions(options *option.QueryOptions) Option {
return OptionFunction(func(selector *Selector) error {
if selector.Options == nil {
selector.Options = options
return nil
}
return errOptionAlreadySet
})
}