-
Notifications
You must be signed in to change notification settings - Fork 7
/
plans.go
114 lines (94 loc) · 2.83 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
103
104
105
106
107
108
109
110
111
112
113
114
package cherrygo
import (
"fmt"
"strconv"
"strings"
)
const basePlanPath = "/v1/teams"
const endPlanPath = "plans"
// GetPlans interface metodas isgauti team'sus
type GetPlans interface {
List(teamID int) ([]Plans, *Response, error)
}
// Plans tai ka grazina api
type Plans struct {
ID int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Custom bool `json:"custom,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"`
}
// Pricing2 specifies fields for specs
type Pricing2 struct {
Price float32 `json:"price,omitempty"`
Currency string `json:"currency,omitempty"`
Taxed bool `json:"taxed,omitempty"`
Unit string `json:"unit,omitempty"`
}
// AvailableRegions specifies fields for specs
type AvailableRegions struct {
ID int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
RegionIso2 string `json:"region_iso_2,omitempty"`
StockQty int `json:"stock_qty,omitempty"`
}
// PlansClient paveldi client
type PlansClient struct {
client *Client
}
// List func lists teams
func (p *PlansClient) List(teamID int) ([]Plans, *Response, error) {
//root := new(teamRoot)
teamIDString := strconv.Itoa(teamID)
plansPath := strings.Join([]string{basePlanPath, teamIDString, endPlanPath}, "/")
var trans []Plans
resp, err := p.client.MakeRequest("GET", plansPath, nil, &trans)
if err != nil {
err = fmt.Errorf("Error: %v", err)
}
return trans, resp, err
}