forked from digitalocean/godo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimages.go
47 lines (38 loc) · 1007 Bytes
/
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
package godo
// ImagesService handles communication with the image related methods of the
// DigitalOcean API.
type ImagesService struct {
client *Client
}
// 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
}
func (i Image) String() string {
return Stringify(i)
}
// List all sizes
func (s *ImagesService) List() ([]Image, *Response, error) {
path := "v2/images"
req, err := s.client.NewRequest("GET", path, nil)
if err != nil {
return nil, nil, err
}
images := new(imagesRoot)
resp, err := s.client.Do(req, images)
if err != nil {
return nil, resp, err
}
return images.Images, resp, err
}