|
| 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 | +} |
0 commit comments