Created
March 5, 2020 17:58
-
-
Save clarkmcc/d864f903e2e7edb385d8db77cf6180f8 to your computer and use it in GitHub Desktop.
Golang function to determine whether a MacOS 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( | |
"getconf", | |
"LONG_BIT", | |
) | |
output, err := cmd.CombinedOutput() | |
if err != nil { | |
log.Printf("error getting arch: %v", err) | |
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