Debian Codegraph @

internal/platform/platform.go

raw symbols SCIP
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 // SelectVersion extracts the platform-appropriate version from a list of strings like
20 // `linux:6.1` or `windows:0.20.0`.
21 //
22 // Returns an empty string and nil if no version matched or an error if no strings were passed.
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 // Allow version numbers without a GOOS prefix on Linux.
37 return version, nil
38 }
39 }
40
41 return "", nil
42 }