Created
March 5, 2020 17:56
-
-
Save clarkmcc/39174701aba1e38fbaaf0dc1e17b7e66 to your computer and use it in GitHub Desktop.
Golang function to determine whether a windows machine is 32 bit or 64 bit.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func GetArch() (string, *errors.ErrorCode) { | |
cmd := exec.Command( | |
"wmic", | |
"os", | |
"get", | |
"osarchitecture", | |
) | |
output, err := cmd.CombinedOutput() | |
if err != nil { | |
return "", errors.New(errors.UnsupportedArchitecture) | |
} | |
is64 := strings.Index(string(output), "64") | |
is32 := strings.Index(string(output), "32") | |
if is32 < 0 && is64 < 0 { | |
return "", errors.New(errors.UnsupportedArchitecture) | |
} | |
if is32 >= 0 { | |
return "32", nil | |
} else if is64 >= 0 { | |
return "64", nil | |
} | |
return "", errors.New(errors.UnsupportedArchitecture) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment