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
|
|
|
// SizesService is an interface for interfacing with the size
|
|
|
|
// endpoints of the DigitalOcean API
|
|
|
|
// See: https://developers.digitalocean.com/documentation/v2#sizes
|
|
|
|
type SizesService interface {
|
2017-05-15 15:54:16 +02:00
|
|
|
List(context.Context, *ListOptions) ([]Size, *Response, error)
|
2016-01-29 20:53:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// SizesServiceOp handles communication with the size related methods of the
|
|
|
|
// DigitalOcean API.
|
|
|
|
type SizesServiceOp struct {
|
|
|
|
client *Client
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ SizesService = &SizesServiceOp{}
|
|
|
|
|
|
|
|
// Size represents a DigitalOcean Size
|
|
|
|
type Size struct {
|
|
|
|
Slug string `json:"slug,omitempty"`
|
|
|
|
Memory int `json:"memory,omitempty"`
|
|
|
|
Vcpus int `json:"vcpus,omitempty"`
|
|
|
|
Disk int `json:"disk,omitempty"`
|
|
|
|
PriceMonthly float64 `json:"price_monthly,omitempty"`
|
|
|
|
PriceHourly float64 `json:"price_hourly,omitempty"`
|
|
|
|
Regions []string `json:"regions,omitempty"`
|
|
|
|
Available bool `json:"available,omitempty"`
|
|
|
|
Transfer float64 `json:"transfer,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s Size) String() string {
|
|
|
|
return Stringify(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
type sizesRoot struct {
|
|
|
|
Sizes []Size
|
|
|
|
Links *Links `json:"links"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// List all images
|
2017-05-15 15:54:16 +02:00
|
|
|
func (s *SizesServiceOp) List(ctx context.Context, opt *ListOptions) ([]Size, *Response, error) {
|
2016-01-29 20:53:56 +01:00
|
|
|
path := "v2/sizes"
|
|
|
|
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(sizesRoot)
|
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.Sizes, resp, err
|
|
|
|
}
|