1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | package main |
9 | |
10 | import ( |
11 | "bytes" |
12 | "context" |
13 | exec "golang.org/x/sys/execabs" |
14 | "runtime" |
15 | "strings" |
16 | ) |
17 | |
18 | |
19 | var arch = func() string { |
20 | cmd := exec.Command("uname", "-m") |
21 | if runtime.GOOS == "windows" { |
22 | cmd = exec.Command("powershell", "-command", "(Get-WmiObject -Class Win32_ComputerSystem).SystemType") |
23 | } |
24 | |
25 | out, err := cmd.Output() |
26 | if err != nil { |
27 | |
28 | return "amd64" |
29 | } |
30 | if bytes.Contains(out, []byte("64")) { |
31 | return "amd64" |
32 | } |
33 | return "386" |
34 | }() |
35 | |
36 | func findGo(ctx context.Context, cmd string) (string, error) { |
37 | out, err := exec.CommandContext(ctx, cmd, "go").CombinedOutput() |
38 | return strings.TrimSpace(string(out)), err |
39 | } |
40 | |