Skip to content

Commit 6ddcd5b

Browse files
committed
Bumped v0.19.0
Signed-off-by: Vishal Rana <[email protected]>
1 parent 39c0752 commit 6ddcd5b

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed

geocode.go

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package labstack
2+
3+
type (
4+
GeocodeAddressRequest struct {
5+
Location string `json:"location"`
6+
Longitude float64 `json:"longitude"`
7+
Latitude float64 `json:"latitude"`
8+
OSMTag string `json:"osm_tag"`
9+
Language string `json:"language"`
10+
Limit int `json:"limit"`
11+
}
12+
13+
GeocodeIPRequest struct {
14+
IP string `json:"ip"`
15+
}
16+
17+
GeocodeReverseRequest struct {
18+
Longitude float64 `json:"longitude"`
19+
Latitude float64 `json:"latitude"`
20+
Language string `json:"language"`
21+
Limit int `json:"limit"`
22+
}
23+
24+
GeocodeResponse struct {
25+
Type string `json:"type"`
26+
Features []*GeocodeFeature `json:"features"`
27+
}
28+
29+
GeocodeFeature struct {
30+
Type string `json:"type"`
31+
Geometry *GeocodeGeometry `json:"geometry"`
32+
Properties Properties `json:"properties"`
33+
}
34+
35+
GeocodeGeometry struct {
36+
Type string `json:"type"`
37+
Coordinates []float64 `json:"coordinates"`
38+
}
39+
)
40+
41+
func (c *Client) GeocodeAddress(req *GeocodeAddressRequest) (*GeocodeResponse, *APIError) {
42+
res := new(GeocodeResponse)
43+
err := new(APIError)
44+
r, e := c.resty.R().
45+
SetBody(req).
46+
SetResult(res).
47+
SetError(err).
48+
Post("/geocode/address")
49+
if e != nil {
50+
return nil, &APIError{
51+
Message: e.Error(),
52+
}
53+
}
54+
if c.error(r) {
55+
return nil, err
56+
}
57+
return res, nil
58+
}
59+
60+
func (c *Client) GeocodeIP(req *GeocodeIPRequest) (*GeocodeResponse, *APIError) {
61+
res := new(GeocodeResponse)
62+
err := new(APIError)
63+
r, e := c.resty.R().
64+
SetBody(req).
65+
SetResult(res).
66+
SetError(err).
67+
Post("/geocode/ip")
68+
if e != nil {
69+
return nil, &APIError{
70+
Message: e.Error(),
71+
}
72+
}
73+
if c.error(r) {
74+
return nil, err
75+
}
76+
return res, nil
77+
}
78+
79+
func (c *Client) GeocodeReverse(req *GeocodeReverseRequest) (*GeocodeResponse, *APIError) {
80+
res := new(GeocodeResponse)
81+
err := new(APIError)
82+
r, e := c.resty.R().
83+
SetBody(req).
84+
SetResult(res).
85+
SetError(err).
86+
Post("/geocode/reverse")
87+
if e != nil {
88+
return nil, &APIError{
89+
Message: e.Error(),
90+
}
91+
}
92+
if c.error(r) {
93+
return nil, err
94+
}
95+
return res, nil
96+
}

properties.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package labstack
2+
3+
type (
4+
Properties map[string]interface{}
5+
)
6+
7+
func (p Properties) Bool(key string) bool {
8+
if val, ok := p[key]; ok {
9+
return val.(bool)
10+
}
11+
return false
12+
}
13+
14+
func (p Properties) String(key string) string {
15+
if val, ok := p[key]; ok {
16+
return val.(string)
17+
}
18+
return ""
19+
}
20+
21+
func (p Properties) Float64(key string) float64 {
22+
if val, ok := p[key]; ok {
23+
return val.(float64)
24+
}
25+
return 0
26+
}

0 commit comments

Comments
 (0)