-
Notifications
You must be signed in to change notification settings - Fork 0
/
env.go
119 lines (110 loc) · 2.01 KB
/
env.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package main
import (
"strings"
)
type GoOS string
const (
Windows = GoOS("windows")
MacOS = GoOS("darwin")
Linux = GoOS("linux")
FreeBSD = GoOS("freebsd")
OpenBSD = GoOS("openbsd")
UnknownOS = GoOS("unknown")
)
type GoArch string
const (
X86 = GoArch("386")
Amd64 = GoArch("amd64")
Arm = GoArch("arm")
Arm64 = GoArch("arm64")
Mips64 = GoArch("mips64")
Mips = GoArch("mips")
MipsLE = GoArch("mipsle")
UnknownArch = GoArch("unknown")
)
func parseOS(rawOS string) GoOS {
osStr := strings.ToLower(rawOS)
switch osStr {
case "windows", "win":
return Windows
case "darwin", "mac", "macos", "osx":
return MacOS
case "linux", "debian", "ubuntu", "redhat", "centos":
return Linux
case "freebsd":
return FreeBSD
case "openbsd":
return OpenBSD
default:
return UnknownOS
}
}
func parseArch(rawArch string) GoArch {
archStr := strings.ToLower(rawArch)
switch archStr {
case "x86", "386", "i386":
return X86
case "amd64", "x86-64", "x64":
return Amd64
case "arm":
return Arm
case "arm64":
return Arm64
case "mips":
return Mips
case "mipsle":
return MipsLE
case "mips64":
return Mips64
default:
return UnknownArch
}
}
func getSuffix(os GoOS, arch GoArch) string {
suffix := "-custom"
switch os {
case Windows:
switch arch {
case X86:
suffix = "-windows-32"
case Amd64:
suffix = "-windows-64"
}
case MacOS:
suffix = "-macos"
case Linux:
switch arch {
case X86:
suffix = "-linux-32"
case Amd64:
suffix = "-linux-64"
case Arm:
suffix = "-linux-arm"
case Arm64:
suffix = "-linux-arm64"
case Mips64:
suffix = "-linux-mips64"
case Mips:
suffix = "-linux-mips"
case MipsLE:
suffix = "-linux-mipsle"
}
case FreeBSD:
switch arch {
case X86:
suffix = "-freebsd-32"
case Amd64:
suffix = "-freebsd-64"
case Arm:
suffix = "-freebsd-arm"
}
case OpenBSD:
switch arch {
case X86:
suffix = "-openbsd-32"
case Amd64:
suffix = "-openbsd-64"
}
}
return suffix
}