-
Notifications
You must be signed in to change notification settings - Fork 224
/
vmSizes.go
47 lines (37 loc) · 889 Bytes
/
vmSizes.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 presenters
import (
"fmt"
"github.com/superfly/flyctl/api"
)
type VMSizes struct {
VMSizes []api.VMSize
}
func (p *VMSizes) APIStruct() interface{} {
return p.VMSizes
}
func (p *VMSizes) FieldNames() []string {
return []string{"Name", "CPU Cores", "Memory"}
}
func (p *VMSizes) Records() []map[string]string {
out := []map[string]string{}
for _, size := range p.VMSizes {
out = append(out, map[string]string{
"Name": size.Name,
"CPU Cores": formatCores(size),
"Memory": formatMemory(size),
})
}
return out
}
func formatCores(size api.VMSize) string {
if size.CPUCores < 1.0 {
return fmt.Sprintf("%.2f", size.CPUCores)
}
return fmt.Sprintf("%d", int(size.CPUCores))
}
func formatMemory(size api.VMSize) string {
if size.MemoryGB < 1.0 {
return fmt.Sprintf("%d MB", size.MemoryMB)
}
return fmt.Sprintf("%d GB", int(size.MemoryGB))
}