forked from braintree-go/braintree-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearch.go
61 lines (52 loc) · 1.33 KB
/
search.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 braintree
import (
"encoding/xml"
)
type SearchQuery struct {
XMLName string `xml:"search"`
Fields []interface{}
}
type SearchResults struct {
XMLName string `xml:"search-results"`
PageSize string `xml:"page-size"`
Ids struct {
Item []string `xml:"item"`
} `xml:"ids"`
}
type TextField struct {
XMLName xml.Name
Is string `xml:"is,omitempty"`
IsNot string `xml:"is-not,omitempty"`
StartsWith string `xml:"starts-with,omitempty"`
EndsWith string `xml:"ends-with,omitempty"`
Contains string `xml:"contains,omitempty"`
}
type RangeField struct {
XMLName xml.Name
Is float64 `xml:"is,omitempty"`
Min float64 `xml:"min,omitempty"`
Max float64 `xml:"max,omitempty"`
}
type MultiField struct {
XMLName xml.Name
Type string `xml:"type,attr"` // type=array
Items []string `xml:"item"`
}
func (s *SearchQuery) AddTextField(field string) *TextField {
f := &TextField{XMLName: xml.Name{Local: field}}
s.Fields = append(s.Fields, f)
return f
}
func (s *SearchQuery) AddRangeField(field string) *RangeField {
f := &RangeField{XMLName: xml.Name{Local: field}}
s.Fields = append(s.Fields, f)
return f
}
func (s *SearchQuery) AddMultiField(field string) *MultiField {
f := &MultiField{
XMLName: xml.Name{Local: field},
Type: "array",
}
s.Fields = append(s.Fields, f)
return f
}