forked from linode/linodego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
90 lines (77 loc) · 2.44 KB
/
types.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package linodego
import (
"context"
"fmt"
)
// LinodeType represents a linode type object
type LinodeType struct {
ID string `json:"id"`
Disk int `json:"disk"`
Class LinodeTypeClass `json:"class"` // enum: nanode, standard, highmem, dedicated
Price *LinodePrice `json:"price"`
Label string `json:"label"`
Addons *LinodeAddons `json:"addons"`
NetworkOut int `json:"network_out"`
Memory int `json:"memory"`
Transfer int `json:"transfer"`
VCPUs int `json:"vcpus"`
}
// LinodePrice represents a linode type price object
type LinodePrice struct {
Hourly float32 `json:"hourly"`
Monthly float32 `json:"monthly"`
}
// LinodeBackupsAddon represents a linode backups addon object
type LinodeBackupsAddon struct {
Price *LinodePrice `json:"price"`
}
// LinodeAddons represent the linode addons object
type LinodeAddons struct {
Backups *LinodeBackupsAddon `json:"backups"`
}
// LinodeTypeClass constants start with Class and include Linode API Instance Type Classes
type LinodeTypeClass string
// LinodeTypeClass contants are the Instance Type Classes that an Instance Type can be assigned
const (
ClassNanode LinodeTypeClass = "nanode"
ClassStandard LinodeTypeClass = "standard"
ClassHighmem LinodeTypeClass = "highmem"
ClassDedicated LinodeTypeClass = "dedicated"
)
// LinodeTypesPagedResponse represents a linode types API response for listing
type LinodeTypesPagedResponse struct {
*PageOptions
Data []LinodeType `json:"data"`
}
func (LinodeTypesPagedResponse) endpoint(c *Client) string {
endpoint, err := c.Types.Endpoint()
if err != nil {
panic(err)
}
return endpoint
}
func (resp *LinodeTypesPagedResponse) appendData(r *LinodeTypesPagedResponse) {
resp.Data = append(resp.Data, r.Data...)
}
// ListTypes lists linode types
func (c *Client) ListTypes(ctx context.Context, opts *ListOptions) ([]LinodeType, error) {
response := LinodeTypesPagedResponse{}
err := c.listHelper(ctx, &response, opts)
if err != nil {
return nil, err
}
return response.Data, nil
}
// GetType gets the type with the provided ID
func (c *Client) GetType(ctx context.Context, typeID string) (*LinodeType, error) {
e, err := c.Types.Endpoint()
if err != nil {
return nil, err
}
e = fmt.Sprintf("%s/%s", e, typeID)
r, err := coupleAPIErrors(c.Types.R(ctx).Get(e))
if err != nil {
return nil, err
}
return r.Result().(*LinodeType), nil
}