| 1 |
package platform |
| 2 |
|
| 3 |
import ( |
| 4 |
"errors" |
| 5 |
"runtime" |
| 6 |
"strings" |
| 7 |
) |
| 8 |
|
| 9 |
const ( |
| 10 |
Linux = "linux" |
| 11 |
Windows = "windows" |
| 12 |
) |
| 13 |
|
| 14 |
const ( |
| 15 |
IsLinux = runtime.GOOS == "linux" |
| 16 |
IsWindows = runtime.GOOS == "windows" |
| 17 |
) |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
func SelectVersion(versions []string) (string, error) { |
| 24 |
const prefix = runtime.GOOS + ":" |
| 25 |
|
| 26 |
if len(versions) == 0 { |
| 27 |
return "", errors.New("no versions specified") |
| 28 |
} |
| 29 |
|
| 30 |
for _, version := range versions { |
| 31 |
if after, ok := strings.CutPrefix(version, prefix); ok { |
| 32 |
return after, nil |
| 33 |
} |
| 34 |
|
| 35 |
if IsLinux && !strings.ContainsRune(version, ':') { |
| 36 |
|
| 37 |
return version, nil |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
return "", nil |
| 42 |
} |