-
Notifications
You must be signed in to change notification settings - Fork 7
/
plans.go
102 lines (85 loc) · 2.6 KB
/
plans.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
91
92
93
94
95
96
97
98
99
100
101
102
package cherrygo
import (
"fmt"
)
const basePlanPath = "/v1/teams"
// PlansService is an interface for interfacing with the Plan endpoints of the CherryServers API
// See: https://api.cherryservers.com/doc/#tag/Plans
type PlansService interface {
List(teamID int, opts *GetOptions) ([]Plan, *Response, error)
}
type Plan struct {
ID int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Slug string `json:"slug,omitempty"`
Custom bool `json:"custom,omitempty"`
Type string `json:"type,omitempty"`
Specs Specs `json:"specs,omitempty"`
Pricing []Pricing `json:"pricing,omitempty"`
AvailableRegions []AvailableRegions `json:"available_regions,omitempty"`
}
// Specs specifies fields for specs
type Specs struct {
Cpus Cpus `json:"cpus,omitempty"`
Memory Memory `json:"memory,omitempty"`
Storage []Storage `json:"storage,omitempty"`
Raid Raid `json:"raid,omitempty"`
Nics Nics `json:"nics,omitempty"`
Bandwidth Bandwidth `json:"bandwidth,omitempty"`
}
// Cpus fields
type Cpus struct {
Count int `json:"count,omitempty"`
Name string `json:"name,omitempty"`
Cores int `json:"cores,omitempty"`
Frequency float32 `json:"frequency,omitempty"`
Unit string `json:"unit,omitempty"`
}
// Memory fields
type Memory struct {
Count int `json:"count,omitempty"`
Total int `json:"total,omitempty"`
Unit string `json:"unit,omitempty"`
Name string `json:"name,omitempty"`
}
// Storage fields
type Storage struct {
Count int `json:"count,omitempty"`
Name string `json:"name,omitempty"`
Size float32 `json:"size,omitempty"`
Unit string `json:"unit,omitempty"`
}
// Raid fields
type Raid struct {
Name string `json:"name,omitempty"`
}
// Nics fields
type Nics struct {
Name string `json:"name,omitempty"`
}
// Bandwidth fields
type Bandwidth struct {
Name string `json:"name,omitempty"`
}
type AvailableRegions struct {
*Region
StockQty int `json:"stock_qty,omitempty"`
SpotQty int `json:"spot_qty,omitempty"`
}
type PlansClient struct {
client *Client
}
// List func lists plans
func (p *PlansClient) List(teamID int, opts *GetOptions) ([]Plan, *Response, error) {
basePath := "/v1/plans"
if teamID != 0 {
basePath = fmt.Sprintf("%s/%d/plans", basePlanPath, teamID)
}
path := opts.WithQuery(basePath)
var trans []Plan
resp, err := p.client.MakeRequest("GET", path, nil, &trans)
if err != nil {
err = fmt.Errorf("Error: %v", err)
}
return trans, resp, err
}