generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 3
/
location.go
35 lines (31 loc) · 845 Bytes
/
location.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
package client
import (
"context"
"encoding/json"
"fmt"
)
const (
locationsEndpoint string = "v1/locations"
)
type Location struct {
City string `json:"city"`
Country string `json:"country"`
Latitude float32 `json:"latitude"`
Longitude float32 `json:"longitude"`
Name string `json:"name"`
State string `json:"state"`
Status string `json:"status"`
}
func GetLocation(ctx context.Context, c *Client, lName string) (*Location, error) {
location := &Location{}
url := fmt.Sprintf("%s/%s/%s", c.BaseURL, locationsEndpoint, lName)
resp, err := c.Get(ctx, url, nil)
if err != nil {
return nil, fmt.Errorf("could not get location %s: %v", lName, err)
}
err = json.Unmarshal(resp, location)
if err != nil {
return nil, fmt.Errorf("could not parse location response: %v", err)
}
return location, nil
}