-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtypes.go
99 lines (83 loc) · 2.28 KB
/
types.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
package fireactions
import (
"errors"
)
var (
// ErrPoolNotFound is returned when a pool is not found
ErrPoolNotFound = errors.New("pool not found")
)
// Pool represents a slice of Pool
type Pools []*Pool
// Pool represents a pool of GitHub runners
type Pool struct {
Name string `json:"name"`
MaxRunners int `json:"max_runners"`
MinRunners int `json:"min_runners"`
CurRunners int `json:"cur_runners"`
Status PoolStatus `json:"status"`
}
// PoolState represents the state of a pool
type PoolState string
// String returns the string representation of the pool state
func (p PoolState) String() string {
return string(p)
}
const (
// PoolStateActive represents the active state, meaning the pool is running
PoolStateActive PoolState = "Active"
// PoolStatePaused represents the paused state, meaning the pool is stopped
PoolStatePaused PoolState = "Paused"
)
// PoolStatus represents the status of a pool
type PoolStatus struct {
State PoolState `json:"state"`
Message string `json:"message"`
}
func (p *Pool) Cols() []string {
return []string{"Name", "Max Runners", "Min Runners", "Cur Runners", "State"}
}
func (p *Pool) ColsMap() map[string]string {
return map[string]string{
"Name": "Name",
"MaxRunners": "Max Runners",
"MinRunners": "Min Runners",
"CurRunners": "Cur Runners",
"State": "State",
}
}
func (p *Pool) KV() []map[string]interface{} {
return []map[string]interface{}{
{
"Name": p.Name,
"Max Runners": p.MaxRunners,
"Min Runners": p.MinRunners,
"Cur Runners": p.CurRunners,
"State": p.Status.State,
},
}
}
func (p Pools) Cols() []string {
return []string{"Name", "Max Runners", "Min Runners", "Cur Runners", "State"}
}
func (p Pools) ColsMap() map[string]string {
return map[string]string{
"Name": "Name",
"MaxRunners": "Max Runners",
"MinRunners": "Min Runners",
"CurRunners": "Cur Runners",
"State": "State",
}
}
func (p Pools) KV() []map[string]interface{} {
kv := make([]map[string]interface{}, 0, len(p))
for _, pool := range p {
kv = append(kv, map[string]interface{}{
"Name": pool.Name,
"Max Runners": pool.MaxRunners,
"Min Runners": pool.MinRunners,
"Cur Runners": pool.CurRunners,
"State": pool.Status.State,
})
}
return kv
}