-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathoptions.go
More file actions
72 lines (57 loc) · 1.74 KB
/
options.go
File metadata and controls
72 lines (57 loc) · 1.74 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package filter
import (
"errors"
)
// Option is the function that allows to set configuration options.
type Option func(p *Processor) error
// WithFieldNameTag allows to use the field names specified by the tag instead of the original struct names.
//
// Note that this is evaluated against the value before the first comma in the field definition.
// For example if a field is defined as: `json:my_field,omitempty`, the evaluated tag value is `my_field`.
//
// Returns an error if the tag is empty.
func WithFieldNameTag(tag string) Option {
return func(p *Processor) error {
if tag == "" {
return errors.New("tag cannot be empty")
}
p.fields.fieldTag = tag
return nil
}
}
// WithQueryFilterKey sets the query parameter key that Processor.ParseURLQuery() looks for.
func WithQueryFilterKey(key string) Option {
return func(p *Processor) error {
if key == "" {
return errors.New("query filter key cannot be empty")
}
p.urlQueryFilterKey = key
return nil
}
}
// WithMaxRules sets the maximum number of rules to pass to the Processor.Apply() function without errors.
// If this option is not set, it defaults to 3.
//
// Return an error if rulemax is less than 1.
func WithMaxRules(rulemax uint) Option {
return func(p *Processor) error {
if rulemax < 1 {
return errors.New("max Rules must be at least 1")
}
p.maxRules = rulemax
return nil
}
}
// WithMaxResults sets the maximum length of the slice returned by Apply() and ApplySubset().
func WithMaxResults(resmax uint) Option {
return func(p *Processor) error {
if resmax < 1 {
return errors.New("maxResults must be at least 1")
}
if resmax > MaxResults {
return errors.New("maxResults must be less than MaxResults")
}
p.maxResults = resmax
return nil
}
}