package util import ( "errors" "fmt" "runtime" "golang.org/x/sys/windows/registry" ) func OSVersion() (string, error) { switch osName := runtime.GOOS; osName { case "windows": verKey, err := registry.OpenKey(registry.LOCAL_MACHINE, "Software\\Microsoft\\Windows NT\\CurrentVersion", registry.QUERY_VALUE) if err != nil { return "", err } major, _, err := verKey.GetIntegerValue("CurrentMajorVersionNumber") if err != nil { return "", err } minor, _, err := verKey.GetIntegerValue("CurrentMinorVersionNumber") if err != nil { return "", err } return fmt.Sprintf("%d.%d", major, minor), nil } return "", errors.New("unknown OS") }