-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
232 lines (194 loc) · 5.21 KB
/
main.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
package main
import (
"fmt"
"github.com/razorcorp/postcode-sdk-go"
"github.com/razorcorp/postcode-sdk-go/postcode"
)
/**
* Package name: main
* Project name: postcode-sdk-go
* Created by: Praveen Premaratne
* Created on: 05/09/2021 15:50
*/
func executor(title string, f func()) {
fmt.Printf("===== %s =====\n", title)
f()
for i := 0; i < 100; i++ {
fmt.Print("*")
}
fmt.Printf("\n\n")
}
func postcodeLookup() {
data, lookupError := postcode.Lookup("RG122PE")
if lookupError != nil {
panic(fmt.Sprintf("%#v", lookupError))
}
fmt.Printf("%#v\n", data)
}
func bulkPostcodeLookup() {
postcodes := postcode.Postcodes{Postcodes: []string{"RG122PE", "GU479DZ"}}
data, lookupError := postcode.BulkLookup(postcodes, nil)
if lookupError != nil {
panic(fmt.Sprintf("%#v", lookupError))
}
fmt.Printf("%#v\n", data)
}
func reverseGeocoding() {
geocode := &postcode.Geocode{
Longitude: 0.629834723775309,
Latitude: 51.7923246977375,
Radius: 100,
}
data, lookupError := postcode.ReverseGeocoding(*geocode)
if lookupError != nil {
panic(fmt.Sprintf("%#v", lookupError))
}
fmt.Printf("%#v\n", len(data))
fmt.Printf("%#v\n", data)
}
func bulkReverseGeocoding() {
geocodes := &postcode.Geocodes{Geolocations: []postcode.Geocode{
{
Longitude: -0.740895,
Latitude: 51.417093,
Radius: 0,
},
{
Longitude: -0.797388,
Latitude: 51.343969,
Radius: 0,
},
}}
data, lookupError := postcode.BulkReverseGeocoding(*geocodes, nil)
if lookupError != nil {
panic(fmt.Sprintf("%#v", lookupError))
}
fmt.Printf("%#v\n", data)
}
func queryPostcode() {
limit := int64(3)
data, lookupError := postcode.Query("RG122P", &limit)
if lookupError != nil {
panic(fmt.Sprintf("%#v", lookupError))
}
fmt.Printf("%#v\n", len(data))
fmt.Printf("%#v\n", data)
}
func validatePostcode() {
data, lookupError := postcode.Validation("RG122PE")
if lookupError != nil {
panic(fmt.Sprintf("%#v", lookupError))
}
fmt.Printf("%#v\n", data)
}
func nearestPostcode() {
limit := int64(5)
radius := int64(200)
data, lookupError := postcode.NearestPostcode("RG122PE", &limit, &radius)
if lookupError != nil {
panic(fmt.Sprintf("%#v", lookupError))
}
fmt.Printf("%#v\n", len(data))
fmt.Printf("%#v\n", data)
}
func autocompletePostcode() {
limit := int64(5)
data, lookupError := postcode.Autocomplete("RG122P", &limit)
if lookupError != nil {
panic(fmt.Sprintf("%#v", lookupError))
}
fmt.Printf("%#v\n", len(data))
fmt.Printf("%#v\n", data)
}
func randomPostcode() {
outCode := "RG12"
data, lookupError := postcode.RandomPostcode(&outCode)
if lookupError != nil {
panic(fmt.Sprintf("%#v", lookupError))
}
fmt.Printf("%#v\n", data)
}
func outcodeLookup() {
data, lookupError := postcode.OutcodeLookup("RG42")
if lookupError != nil {
panic(fmt.Sprintf("%#v", lookupError))
}
fmt.Printf("%#v\n", data)
}
func outcodeReverseGeocoding() {
geocode := &postcode.Geocode{
Longitude: -0.740895,
Latitude: 51.417093,
Radius: 10000,
}
data, lookupError := postcode.OutcodeReverseGeocoding(*geocode)
if lookupError != nil {
panic(fmt.Sprintf("%#v", lookupError))
}
fmt.Printf("%#v\n", data)
}
func nearestOutcode() {
limit := int64(5)
radius := int64(200)
data, lookupError := postcode.NearestOutcode("RG12", &limit, &radius)
if lookupError != nil {
panic(fmt.Sprintf("%#v", lookupError))
}
fmt.Printf("%#v\n", len(data))
fmt.Printf("%#v\n", data)
}
func scottishPostcodeLookup() {
data, lookupError := postcode.ScottishPostcodeLookup("EH12 8NF")
if lookupError != nil {
panic(fmt.Sprintf("%#v", lookupError))
}
fmt.Printf("%#v\n", data)
}
func terminatedPostcodeLookup() {
data, lookupError := postcode.TerminatedPostcodeLookup("E1W 1UU")
if lookupError != nil {
panic(fmt.Sprintf("%#v", lookupError))
}
fmt.Printf("%#v\n", data)
}
func placeLookup() {
data, lookupError := postcode.PlaceLookup("osgb4000000074546114")
if lookupError != nil {
panic(fmt.Sprintf("%#v", lookupError))
}
fmt.Printf("%#v\n", data)
}
func placeQuery() {
data, lookupError := postcode.PlaceQuery("Bracknell", nil)
if lookupError != nil {
panic(fmt.Sprintf("%#v", lookupError))
}
fmt.Printf("%#v\n", data)
}
func randomPlace() {
data, lookupError := postcode.RandomPlace()
if lookupError != nil {
panic(fmt.Sprintf("%#v", lookupError))
}
fmt.Printf("%#v\n", data)
}
func main() {
fmt.Printf("Version: %s\n", postcode.VERSION)
executor("Singe postcode lookup", postcodeLookup)
executor("Bulk postcode lookup", bulkPostcodeLookup)
executor("Reverse Geocoding lookup", reverseGeocoding)
executor("Bulk reverse Geocoding lookup", bulkReverseGeocoding)
executor("Query postcode", queryPostcode)
executor("Validate postcode", validatePostcode)
executor("Nearest postcode", nearestPostcode)
executor("Autocomplete postcode", autocompletePostcode)
executor("Random postcode", randomPostcode)
executor("Outcode lookup", outcodeLookup)
executor("Outcode Reverse Geocoding lookup", outcodeReverseGeocoding)
executor("Nearest Outcode", nearestOutcode)
executor("Scottish postcode lookup", scottishPostcodeLookup)
executor("Terminated postcode lookup", terminatedPostcodeLookup)
executor("Place lookup", placeLookup)
executor("Place query lookup", placeQuery)
executor("Random place", randomPlace)
}