-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
62 lines (50 loc) · 1.05 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
/* Copyright © 2022 Mike Brown. All Rights Reserved.
*
* See LICENSE file at the root of this package for license terms
*/
package internal
type OperatingSystem uint64
const (
OsNone OperatingSystem = iota
Ubuntu22_04
AmazonLinux2
AmazonLinux2023
AmazonLinux2023Min
OsInvalid // must be last
)
var osTab = []string{
OsNone: "",
Ubuntu22_04: "ubuntu22.04",
AmazonLinux2: "amzn2",
AmazonLinux2023: "amzn2023",
AmazonLinux2023Min: "amzn2023min",
OsInvalid: "invalid",
}
var osMap = make(map[string]OperatingSystem)
func (os OperatingSystem) String() string {
idx := int(os)
if idx < 0 || idx > len(osTab) {
idx = int(OsInvalid)
}
return osTab[idx]
}
func OsFromString(osStr string) OperatingSystem {
os, ok := osMap[osStr]
if !ok {
return OsInvalid
}
return os
}
func (os OperatingSystem) Values() []OperatingSystem {
return []OperatingSystem{
Ubuntu22_04,
AmazonLinux2,
AmazonLinux2023,
AmazonLinux2023Min,
}
}
func init() {
for idx, osStr := range osTab {
osMap[osStr] = OperatingSystem(idx)
}
}