1
0
Fork 0
mccl/pkg/util/osversion_unix.go

30 lines
609 B
Go

//go:build unix
// +build unix
package util
import (
"errors"
"os"
"runtime"
"strings"
)
func OSVersion() (string, error) {
switch osName := runtime.GOOS; osName {
case "linux":
// Implemented just in case for future. Guess if it will ever be needed
// then a kernel version will be used to compare against.
osRelease, err := os.ReadFile("/proc/sys/kernel/osrelease")
if err != nil {
return "", err
}
kVer := strings.Split(string(osRelease), "-")
if len(kVer) >= 1 {
return kVer[0], nil
}
return "", errors.New("malformed osrelease")
}
return "", errors.New("unknown OS")
}