-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
postcode.go
executable file
·87 lines (75 loc) · 2.09 KB
/
postcode.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
package postcode
import (
"github.com/m3o/m3o-go/client"
)
func NewPostcodeService(token string) *PostcodeService {
return &PostcodeService{
client: client.NewClient(&client.Options{
Token: token,
}),
}
}
type PostcodeService struct {
client *client.Client
}
// Lookup a postcode to retrieve the related region, county, etc
func (t *PostcodeService) Lookup(request *LookupRequest) (*LookupResponse, error) {
rsp := &LookupResponse{}
return rsp, t.client.Call("postcode", "Lookup", request, rsp)
}
// Return a random postcode and its related info
func (t *PostcodeService) Random(request *RandomRequest) (*RandomResponse, error) {
rsp := &RandomResponse{}
return rsp, t.client.Call("postcode", "Random", request, rsp)
}
// Validate a postcode.
func (t *PostcodeService) Validate(request *ValidateRequest) (*ValidateResponse, error) {
rsp := &ValidateResponse{}
return rsp, t.client.Call("postcode", "Validate", request, rsp)
}
type LookupRequest struct {
// UK postcode e.g SW1A 2AA
Postcode string `json:"postcode"`
}
type LookupResponse struct {
// country e.g United Kingdom
Country string `json:"country"`
// e.g Westminster
District string `json:"district"`
// e.g 51.50354
Latitude float64 `json:"latitude"`
// e.g -0.127695
Longitude float64 `json:"longitude"`
// UK postcode e.g SW1A 2AA
Postcode string `json:"postcode"`
// related region e.g London
Region string `json:"region"`
// e.g St James's
Ward string `json:"ward"`
}
type RandomRequest struct {
}
type RandomResponse struct {
// country e.g United Kingdom
Country string `json:"country"`
// e.g Westminster
District string `json:"district"`
// e.g 51.50354
Latitude float64 `json:"latitude"`
// e.g -0.127695
Longitude float64 `json:"longitude"`
// UK postcode e.g SW1A 2AA
Postcode string `json:"postcode"`
// related region e.g London
Region string `json:"region"`
// e.g St James's
Ward string `json:"ward"`
}
type ValidateRequest struct {
// UK postcode e.g SW1A 2AA
Postcode string `json:"postcode"`
}
type ValidateResponse struct {
// Is the postcode valid (true) or not (false)
Valid bool `json:"valid"`
}