-
Notifications
You must be signed in to change notification settings - Fork 221
/
render.go
51 lines (40 loc) · 1.28 KB
/
render.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
package ips
import (
"context"
"strings"
"github.com/superfly/flyctl/api"
"github.com/superfly/flyctl/cmd/presenters"
"github.com/superfly/flyctl/internal/render"
"github.com/superfly/flyctl/iostreams"
)
func renderListTable(ctx context.Context, ipAddresses []api.IPAddress) {
rows := make([][]string, 0, len(ipAddresses))
var ipType string
for _, ipAddr := range ipAddresses {
if strings.HasPrefix(ipAddr.Address, "fdaa") {
ipType = "private"
} else {
ipType = "public"
}
rows = append(rows, []string{ipAddr.Type, ipAddr.Address, ipType, ipAddr.Region, presenters.FormatRelativeTime(ipAddr.CreatedAt)})
}
out := iostreams.FromContext(ctx).Out
render.Table(out, "", rows, "Version", "IP", "Type", "Region", "Created At")
}
func renderPrivateTable(ctx context.Context, allocations []*api.AllocationStatus, backupRegions []api.Region) {
rows := make([][]string, 0, len(allocations))
for _, alloc := range allocations {
region := alloc.Region
if len(backupRegions) > 0 {
for _, r := range backupRegions {
if alloc.Region == r.Code {
region = alloc.Region + "(B)"
break
}
}
}
rows = append(rows, []string{alloc.IDShort, region, alloc.PrivateIP})
}
out := iostreams.FromContext(ctx).Out
render.Table(out, "", rows, "ID", "Region", "IP")
}