This repository has been archived by the owner on Oct 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.go
97 lines (91 loc) · 2.52 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
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
package wigole
import (
"errors"
"net/url"
"strconv"
)
var errVariance = errors.New("variance must be between 0.001 and 0.2")
// SearchUrl uses the SearchParameters current state to build url.Values.
func (p *SearchParameters) SearchUrl() (values url.Values, err error) {
values = url.Values{}
values.Set("onlymine", strconv.FormatBool(p.Onlymine))
if p.Notmine {
values.Set("notmine", strconv.FormatBool(p.Notmine))
}
if p.Latrange1 != 0 || p.Latrange2 != 0 {
values.Set("latrange1", strconv.FormatFloat(p.Latrange1, 'f', -1, 64))
values.Set("latrange2", strconv.FormatFloat(p.Latrange2, 'f', -1, 64))
}
if p.Longrange1 != 0 || p.Longrange2 != 0 {
values.Set("longrange1", strconv.FormatFloat(p.Longrange1, 'f', -1, 64))
values.Set("longrange2", strconv.FormatFloat(p.Longrange2, 'f', -1, 64))
}
if !p.Lastupdt.IsZero() {
values.Set("lastupdt", TimeString(p.Lastupdt))
}
if !p.StartTransID.IsZero() {
values.Set("startTransID", strconv.Itoa(p.StartTransID.Year()))
}
if !p.EndTransID.IsZero() {
values.Set("endTransID", strconv.Itoa(p.EndTransID.Year()))
}
if p.MinQoS != 8 {
values.Set("minQoS", strconv.Itoa(int(p.MinQoS)))
}
if p.Variance < 0.001 && p.Variance > 0.2 {
values.Set("variance", strconv.FormatFloat(p.Variance, 'f', -1, 64))
} else if p.Variance != 0 {
return url.Values{}, errVariance
}
if len(p.HouseNumber) != 0 {
values.Set("houseNumber", p.HouseNumber)
}
if len(p.Road) != 0 {
values.Set("road", p.Road)
}
if len(p.City) != 0 {
values.Set("city", p.City)
}
if len(p.Region) != 0 {
values.Set("region", p.Region)
}
if len(p.PostalCode) != 0 {
values.Set("postalCode", p.PostalCode)
}
if len(p.Country) != 0 {
values.Set("country", p.Country)
}
if p.ResultsPerPage != 0 {
values.Set("resultsPerPage", strconv.Itoa(int(p.ResultsPerPage)))
}
if len(p.SearchAfter) != 0 {
values.Set("searchAfter", p.SearchAfter)
}
return values, nil
}
// NewSearch initializes a general search parameters.
func NewSearch() *SearchParameters {
return &SearchParameters{
MinQoS: 8,
}
}
// NewSsid initializes and returns a general SSID search.
func NewSsid() *SearchSsid {
s := SearchSsid{}
s.SearchParameters = *NewSearch()
return &s
}
// SsidUrl uses the SearchSsid current state to build url.Values.
func (p *SearchSsid) SsidUrl() (values url.Values, err error) {
values, err = p.SearchParameters.SearchUrl()
if err != nil {
return nil, err
}
if len(p.Ssid) != 0 {
values.Set("ssid", p.Ssid)
}
if len(p.Ssidlike) != 0 {
values.Set("ssidlike", p.Ssidlike)
}
return values, err
}