1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
package windows
import (
"fmt"
"strings"
)
const (
// V1809 is the Windows version that is 1809 and also known as Windows 2019
// ltsc.
V1809 = "1809"
// V2004 is the Windows version that is 2004 sac.
V2004 = "2004"
// V20H2 is the Windows version that is 2009 sac.
V20H2 = "2009"
)
// UnsupportedWindowsVersionError represents that the version specified is not
// supported.
type UnsupportedWindowsVersionError struct {
Version string
}
func NewUnsupportedWindowsVersionError(version string) *UnsupportedWindowsVersionError {
return &UnsupportedWindowsVersionError{Version: version}
}
func (e *UnsupportedWindowsVersionError) Error() string {
return fmt.Sprintf("unsupported Windows Version: %s", e.Version)
}
func (e *UnsupportedWindowsVersionError) Is(err error) bool {
_, ok := err.(*UnsupportedWindowsVersionError)
return ok
}
var supportedWindowsVersions = []string{
V1809,
V2004,
V20H2,
}
var supportedWindowsBuilds = map[string]string{
"10.0.17763": V1809,
"10.0.19041": V2004,
}
// Version checks the specified operatingSystem to see if it's one of the
// supported Windows version. If true, it returns the os version.
// UnsupportedWindowsVersionError is returned when no supported Windows version
// is found in the string.
func Version(operatingSystem string) (string, error) {
for _, windowsVersion := range supportedWindowsVersions {
if strings.Contains(operatingSystem, fmt.Sprintf(" %s ", windowsVersion)) {
return windowsVersion, nil
}
}
windowsVersion, ok := supportedWindowsBuilds[operatingSystem]
if ok {
return windowsVersion, nil
}
return "", NewUnsupportedWindowsVersionError(operatingSystem)
}
|