2016-01-29 20:53:56 +01:00
|
|
|
package godo
|
|
|
|
|
2017-05-15 15:54:16 +02:00
|
|
|
import "github.com/digitalocean/godo/context"
|
|
|
|
|
2016-01-29 20:53:56 +01:00
|
|
|
// RegionsService is an interface for interfacing with the regions
|
|
|
|
// endpoints of the DigitalOcean API
|
|
|
|
// See: https://developers.digitalocean.com/documentation/v2#regions
|
|
|
|
type RegionsService interface {
|
2017-05-15 15:54:16 +02:00
|
|
|
List(context.Context, *ListOptions) ([]Region, *Response, error)
|
2016-01-29 20:53:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// RegionsServiceOp handles communication with the region related methods of the
|
|
|
|
// DigitalOcean API.
|
|
|
|
type RegionsServiceOp struct {
|
|
|
|
client *Client
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ RegionsService = &RegionsServiceOp{}
|
|
|
|
|
|
|
|
// Region represents a DigitalOcean Region
|
|
|
|
type Region struct {
|
|
|
|
Slug string `json:"slug,omitempty"`
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
Sizes []string `json:"sizes,omitempty"`
|
|
|
|
Available bool `json:"available,omitempty"`
|
|
|
|
Features []string `json:"features,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type regionsRoot struct {
|
|
|
|
Regions []Region
|
|
|
|
Links *Links `json:"links"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r Region) String() string {
|
|
|
|
return Stringify(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
// List all regions
|
2017-05-15 15:54:16 +02:00
|
|
|
func (s *RegionsServiceOp) List(ctx context.Context, opt *ListOptions) ([]Region, *Response, error) {
|
2016-01-29 20:53:56 +01:00
|
|
|
path := "v2/regions"
|
|
|
|
path, err := addOptions(path, opt)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
2017-05-15 15:54:16 +02:00
|
|
|
req, err := s.client.NewRequest(ctx, "GET", path, nil)
|
2016-01-29 20:53:56 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
root := new(regionsRoot)
|
2017-05-15 15:54:16 +02:00
|
|
|
resp, err := s.client.Do(ctx, req, root)
|
2016-01-29 20:53:56 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, resp, err
|
|
|
|
}
|
|
|
|
if l := root.Links; l != nil {
|
|
|
|
resp.Links = l
|
|
|
|
}
|
|
|
|
|
|
|
|
return root.Regions, resp, err
|
|
|
|
}
|