-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathcloud_server_flavor.go
43 lines (37 loc) · 1.05 KB
/
cloud_server_flavor.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
package gobizfly
import (
"context"
"encoding/json"
"net/http"
)
// serverFlavorResponse is the response from the server flavor API.
type serverFlavorResponse struct {
ID string `json:"id"`
Name string `json:"name"` // Deprecated: Will be removed in the future.
VCPUs int `json:"vcpus"`
RAM int `json:"ram"`
Disk int `json:"disk"`
Category string `json:"category"`
}
type cloudServerFlavorResource struct {
client *Client
}
func (cs *cloudServerService) Flavors() *cloudServerFlavorResource {
return &cloudServerFlavorResource{client: cs.client}
}
// List lists server flavors
func (s *cloudServerFlavorResource) List(ctx context.Context) ([]*serverFlavorResponse, error) {
req, err := s.client.NewRequest(ctx, http.MethodGet, serverServiceName, flavorPath, nil)
if err != nil {
return nil, err
}
resp, err := s.client.Do(ctx, req)
if err != nil {
return nil, err
}
var flavors []*serverFlavorResponse
if err := json.NewDecoder(resp.Body).Decode(&flavors); err != nil {
return nil, err
}
return flavors, nil
}