From 35a50bd792c06ce73cc345b2139e8fc3425708a0 Mon Sep 17 00:00:00 2001 From: anyanfei <87066062@qq.com> Date: Wed, 20 Jul 2022 17:25:14 +0800 Subject: [PATCH] System: Add the system bits judgment (#44) Co-authored-by: anyanfei --- system/os.go | 6 ++++++ system/os_test.go | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/system/os.go b/system/os.go index 91a1cb9..5b63c07 100644 --- a/system/os.go +++ b/system/os.go @@ -70,3 +70,9 @@ func ExecCommand(command string) (stdout, stderr string, err error) { return } + +// GetOsBits get this system bits 32bit or 64bit +// return bit int (32/64) +func GetOsBits() int { + return 32 << (^uint(0) >> 63) +} diff --git a/system/os_test.go b/system/os_test.go index 5593069..694c33c 100644 --- a/system/os_test.go +++ b/system/os_test.go @@ -60,3 +60,13 @@ func TestExecCommand(t *testing.T) { assert.IsNotNil(err) } } + +func TestGetOsBits(t *testing.T) { + osBits := GetOsBits() + switch osBits { + case 32, 64: + t.Logf("os is %d", osBits) + default: + t.Error("os is not 32 or 64 bits") + } +}