forked from cherryservers/cherrygo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
regions.go
51 lines (40 loc) · 1.4 KB
/
regions.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
package cherrygo
import "fmt"
const baseRegionPath = "/v1/regions"
// RegionsService is an interface for interfacing with the the Images endpoints of the CherryServers API
// See: https://api.cherryservers.com/doc/#tag/Regions
type RegionsService interface {
List(opts *GetOptions) ([]Region, *Response, error)
Get(region string, opts *GetOptions) (Region, *Response, error)
}
// Region fields
type Region struct {
ID int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Slug string `json:"slug,omitempty"`
RegionIso2 string `json:"region_iso_2,omitempty"`
BGP RegionBGP `json:"bgp,omitempty"`
Location string `json:"location,omitempty"`
Href string `json:"href,omitempty"`
}
type RegionsClient struct {
client *Client
}
func (i *RegionsClient) List(opts *GetOptions) ([]Region, *Response, error) {
path := opts.WithQuery(fmt.Sprintf("%s", baseRegionPath))
var trans []Region
resp, err := i.client.MakeRequest("GET", path, nil, &trans)
if err != nil {
err = fmt.Errorf("Error: %v", err)
}
return trans, resp, err
}
func (i *RegionsClient) Get(region string, opts *GetOptions) (Region, *Response, error) {
path := opts.WithQuery(fmt.Sprintf("%s/%s", baseRegionPath, region))
var trans Region
resp, err := i.client.MakeRequest("GET", path, nil, &trans)
if err != nil {
err = fmt.Errorf("Error: %v", err)
}
return trans, resp, err
}