/
filtertype.go
199 lines (168 loc) · 4.8 KB
/
filtertype.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
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
package am
type FilterType struct {
Int32Filters map[string][]int32
Int64Filters map[string][]int64
Float32Filters map[string][]float32
BoolFilters map[string][]bool
StringFilters map[string][]string
}
func (f *FilterType) AddBool(key string, value bool) {
if f.BoolFilters == nil {
f.BoolFilters = make(map[string][]bool)
}
if _, ok := f.BoolFilters[key]; ok {
f.BoolFilters[key] = append(f.BoolFilters[key], value)
} else {
f.BoolFilters[key] = []bool{value}
}
}
func (f *FilterType) AddBools(key string, values []bool) {
if f.BoolFilters == nil {
f.BoolFilters = make(map[string][]bool)
}
if _, ok := f.BoolFilters[key]; ok {
f.BoolFilters[key] = append(f.BoolFilters[key], values...)
} else {
f.BoolFilters[key] = values
}
}
func (f *FilterType) Bool(key string) (bool, bool) {
if f.BoolFilters != nil && len(f.BoolFilters[key]) >= 1 {
return f.BoolFilters[key][0], true
}
return false, false
}
func (f *FilterType) Bools(key string) ([]bool, bool) {
if f.BoolFilters != nil && len(f.BoolFilters[key]) >= 1 {
return f.BoolFilters[key], true
}
return nil, false
}
func (f *FilterType) AddInt32(key string, value int32) {
if f.Int32Filters == nil {
f.Int32Filters = make(map[string][]int32)
}
if _, ok := f.Int32Filters[key]; ok {
f.Int32Filters[key] = append(f.Int32Filters[key], value)
} else {
f.Int32Filters[key] = []int32{value}
}
}
func (f *FilterType) AddInt32s(key string, values []int32) {
if f.Int32Filters == nil {
f.Int32Filters = make(map[string][]int32)
}
if _, ok := f.Int32Filters[key]; ok {
f.Int32Filters[key] = append(f.Int32Filters[key], values...)
} else {
f.Int32Filters[key] = values
}
}
func (f *FilterType) Int32(key string) (int32, bool) {
if f.Int32Filters != nil && len(f.Int32Filters[key]) >= 1 {
return f.Int32Filters[key][0], true
}
return 0, false
}
func (f *FilterType) Int32s(key string) ([]int32, bool) {
if f.Int32Filters != nil && len(f.Int32Filters[key]) >= 1 {
return f.Int32Filters[key], true
}
return nil, false
}
func (f *FilterType) AddInt64(key string, value int64) {
if f.Int64Filters == nil {
f.Int64Filters = make(map[string][]int64)
}
if _, ok := f.Int64Filters[key]; ok {
f.Int64Filters[key] = append(f.Int64Filters[key], value)
} else {
f.Int64Filters[key] = []int64{value}
}
}
func (f *FilterType) AddInt64s(key string, values []int64) {
if f.Int64Filters == nil {
f.Int64Filters = make(map[string][]int64)
}
if _, ok := f.Int64Filters[key]; ok {
f.Int64Filters[key] = append(f.Int64Filters[key], values...)
} else {
f.Int64Filters[key] = values
}
}
func (f *FilterType) Int64(key string) (int64, bool) {
if f.Int64Filters != nil && len(f.Int64Filters[key]) >= 1 {
return f.Int64Filters[key][0], true
}
return 0, false
}
func (f *FilterType) Int64s(key string) ([]int64, bool) {
if f.Int64Filters != nil && len(f.Int64Filters[key]) >= 1 {
return f.Int64Filters[key], true
}
return nil, false
}
func (f *FilterType) AddFloat32(key string, value float32) {
if f.Float32Filters == nil {
f.Float32Filters = make(map[string][]float32)
}
if _, ok := f.Float32Filters[key]; ok {
f.Float32Filters[key] = append(f.Float32Filters[key], value)
} else {
f.Float32Filters[key] = []float32{value}
}
}
func (f *FilterType) AddFloat32s(key string, values []float32) {
if f.Float32Filters == nil {
f.Float32Filters = make(map[string][]float32)
}
if _, ok := f.Float32Filters[key]; ok {
f.Float32Filters[key] = append(f.Float32Filters[key], values...)
} else {
f.Float32Filters[key] = values
}
}
func (f *FilterType) Float32(key string) (float32, bool) {
if f.Float32Filters != nil && len(f.Float32Filters[key]) >= 1 {
return f.Float32Filters[key][0], true
}
return 0, false
}
func (f *FilterType) Float32s(key string) ([]float32, bool) {
if f.Float32Filters != nil && len(f.Float32Filters[key]) >= 1 {
return f.Float32Filters[key], true
}
return nil, false
}
func (f *FilterType) AddString(key, value string) {
if f.StringFilters == nil {
f.StringFilters = make(map[string][]string)
}
if _, ok := f.StringFilters[key]; ok {
f.StringFilters[key] = append(f.StringFilters[key], value)
} else {
f.StringFilters[key] = []string{value}
}
}
func (f *FilterType) AddStrings(key string, values []string) {
if f.StringFilters == nil {
f.StringFilters = make(map[string][]string)
}
if _, ok := f.StringFilters[key]; ok {
f.StringFilters[key] = append(f.StringFilters[key], values...)
} else {
f.StringFilters[key] = values
}
}
func (f *FilterType) String(key string) (string, bool) {
if f.StringFilters != nil && len(f.StringFilters[key]) >= 1 {
return f.StringFilters[key][0], true
}
return "", false
}
func (f *FilterType) Strings(key string) ([]string, bool) {
if f.StringFilters != nil && len(f.StringFilters[key]) >= 1 {
return f.StringFilters[key], true
}
return nil, false
}