forked from digitalocean/godo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
images.go
64 lines (53 loc) · 1.44 KB
/
images.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
52
53
54
55
56
57
58
59
60
61
62
63
64
package godo
// ImagesService is an interface for interfacing with the images
// endpoints of the Digital Ocean API
// See: https://developers.digitalocean.com/documentation/v2#images
type ImagesService interface {
List(*ListOptions) ([]Image, *Response, error)
}
// ImagesServiceOp handles communication with the image related methods of the
// DigitalOcean API.
type ImagesServiceOp struct {
client *Client
}
var _ ImagesService = &ImagesServiceOp{}
// Image represents a DigitalOcean Image
type Image struct {
ID int `json:"id,float64,omitempty"`
Name string `json:"name,omitempty"`
Distribution string `json:"distribution,omitempty"`
Slug string `json:"slug,omitempty"`
Public bool `json:"public,omitempty"`
Regions []string `json:"regions,omitempty"`
}
type imageRoot struct {
Image Image
}
type imagesRoot struct {
Images []Image
Links *Links `json:"links"`
}
func (i Image) String() string {
return Stringify(i)
}
// List all sizes
func (s *ImagesServiceOp) List(opt *ListOptions) ([]Image, *Response, error) {
path := "v2/images"
path, err := addOptions(path, opt)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", path, nil)
if err != nil {
return nil, nil, err
}
root := new(imagesRoot)
resp, err := s.client.Do(req, root)
if err != nil {
return nil, resp, err
}
if l := root.Links; l != nil {
resp.Links = l
}
return root.Images, resp, err
}