-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
option.go
44 lines (37 loc) · 1.32 KB
/
option.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
42
43
44
package query
import "reflect"
// Option represents an option for Query.
type Option func(*Query)
// CaseInsensitive returns the Option to match case insensitivity.
func CaseInsensitive() Option {
return func(q *Query) {
q.caseInsensitive = true
}
}
// ExtractByStructTag returns the Option to allow extracting by struct tag.
func ExtractByStructTag(tagNames ...string) Option {
return func(q *Query) {
q.structTags = append(q.structTags, tagNames...)
}
}
// CustomExtractFunc returns the Option to customize the behavior of extractors.
func CustomExtractFunc(f func(ExtractFunc) ExtractFunc) Option {
return func(q *Query) {
q.customExtractFuncs = append(q.customExtractFuncs, f)
}
}
// CustomStructFieldNameGetter returns the Option to set f as custom function which gets struct field name.
// f is called by Key.Extract to get struct field name, if the target value is a struct.
//
// Deprecated: Use CustomExtractFunc instead.
func CustomStructFieldNameGetter(f func(f reflect.StructField) string) Option {
return func(q *Query) {
q.customStructFieldNameGetter = f
}
}
// CustomIsInlineStructFieldFunc returns the Option to customize the behavior of extractors.
func CustomIsInlineStructFieldFunc(f func(reflect.StructField) bool) Option {
return func(q *Query) {
q.customIsInlineFuncs = append(q.customIsInlineFuncs, f)
}
}