-
Notifications
You must be signed in to change notification settings - Fork 274
/
filter.go
61 lines (50 loc) · 989 Bytes
/
filter.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
package paypal
import (
"fmt"
"time"
)
const format = "2006-01-02T15:04:05Z"
// Filter type
type Filter struct {
fields []fmt.Stringer
}
func (s *Filter) String() string {
var filter string
for i, f := range s.fields {
if i == 0 {
filter = "?" + f.String()
} else {
filter = filter + "&" + f.String()
}
}
return filter
}
// TextField type
type TextField struct {
name string
Is string
}
func (d TextField) String() string {
return fmt.Sprintf("%s=%s", d.name, d.Is)
}
// TimeField type
type TimeField struct {
name string
Is time.Time
}
// String .
func (d TimeField) String() string {
return fmt.Sprintf("%s=%s", d.name, d.Is.UTC().Format(format))
}
// AddTextField .
func (s *Filter) AddTextField(field string) *TextField {
f := &TextField{name: field}
s.fields = append(s.fields, f)
return f
}
// AddTimeField .
func (s *Filter) AddTimeField(field string) *TimeField {
f := &TimeField{name: field}
s.fields = append(s.fields, f)
return f
}