-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocation.go
76 lines (65 loc) · 1.89 KB
/
location.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
package api
import (
"context"
"time"
"github.com/moonrhythm/validator"
)
type Location interface {
List(ctx context.Context, m *LocationList) (*LocationListResult, error)
Get(ctx context.Context, m *LocationGet) (*LocationItem, error)
}
type LocationList struct {
Project string `json:"project" yaml:"project"` // optional
}
type LocationListResult struct {
Items []*LocationItem `json:"items" yaml:"items"`
}
func (m *LocationListResult) Table() [][]string {
table := [][]string{
{"ID", "DOMAIN SUFFIX", "ENDPOINT", "CNAME"},
}
for _, x := range m.Items {
table = append(table, []string{
x.ID,
x.DomainSuffix,
x.Endpoint,
x.CName,
})
}
return table
}
type LocationItem struct {
ID string `json:"id" yaml:"id"`
DomainSuffix string `json:"domainSuffix" yaml:"domainSuffix"`
Endpoint string `json:"endpoint" yaml:"endpoint"`
CName string `json:"cname" yaml:"cname"`
FreeTier bool `json:"freeTier" yaml:"freeTier"`
CPUAllocatable []string `json:"cpuAllocatable" yaml:"cpuAllocatable"`
MemoryAllocatable []string `json:"memoryAllocatable" yaml:"memoryAllocatable"`
Features LocationFeatures `json:"features" yaml:"features"`
CreatedAt time.Time `json:"createdAt" yaml:"createdAt"`
}
func (m *LocationItem) Table() [][]string {
table := [][]string{
{"ID", "DOMAIN SUFFIX", "ENDPOINT", "CNAME"},
{
m.ID,
m.DomainSuffix,
m.Endpoint,
m.CName,
},
}
return table
}
type LocationFeatures struct {
WorkloadIdentity bool `json:"workloadIdentity,omitempty" yaml:"workloadIdentity"`
Disk *struct{} `json:"disk,omitempty" yaml:"disk"`
}
type LocationGet struct {
ID string `json:"id" yaml:"id"`
}
func (m *LocationGet) Valid() error {
v := validator.New()
v.Must(m.ID != "", "id required")
return WrapValidate(v)
}