From 261370e30d91aadc461edffe3c0916697fe388ec Mon Sep 17 00:00:00 2001 From: dudaodong Date: Mon, 17 Jan 2022 16:57:38 +0800 Subject: [PATCH] fix: os.go/ExecCommand make error the last return value --- README.md | 2 +- README_zh-CN.md | 2 +- retry/retry.go | 6 ++++-- system/os.go | 2 +- system/os_test.go | 6 ++++-- validator/validator.go | 2 +- 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index d132b58..13b6063 100644 --- a/README.md +++ b/README.md @@ -535,7 +535,7 @@ func GetOsEnv(key string) string //gets the value of the environment variable na func SetOsEnv(key, value string) error //sets the value of the environment variable named by the key. func RemoveOsEnv(key string) error //remove a single environment variable. func CompareOsEnv(key, comparedEnv string) bool //gets env named by the key and compare it with comparedEnv -func ExecCommand(command string) (err error, stdout, stderr string) //use shell /bin/bash -c to execute command +func ExecCommand(command string) (stdout, stderr string, err error) //use shell /bin/bash -c to execute command ``` ### 13. validator is for data validation diff --git a/README_zh-CN.md b/README_zh-CN.md index 96f8182..8a7baac 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -536,7 +536,7 @@ func GetOsEnv(key string) string //获取名称为key的环境变量 func SetOsEnv(key, value string) error //设置环境变量 func RemoveOsEnv(key string) error //删除指定key的环境变量 func CompareOsEnv(key, comparedEnv string) bool //获取名称为key的环境变量并和comparedEnv比较 -func ExecCommand(command string) (err error, stdout, stderr string) //执行shell命令(/bin/bash) +func ExecCommand(command string) (stdout, stderr string, err error) //执行shell命令(/bin/bash) ``` ### 13. validator验证器包 diff --git a/retry/retry.go b/retry/retry.go index f58c4fe..59bbdfd 100644 --- a/retry/retry.go +++ b/retry/retry.go @@ -15,7 +15,9 @@ import ( ) const ( - DefaultRetryTimes = 5 + // DefaultRetryTimes times of retry + DefaultRetryTimes = 5 + // DefaultRetryDuration time duration of two retries DefaultRetryDuration = time.Second * 3 ) @@ -26,7 +28,7 @@ type RetryConfig struct { retryDuration time.Duration } -// RetryFn is function that retry executes +// RetryFunc is function that retry executes type RetryFunc func() error // Option is for adding retry config diff --git a/system/os.go b/system/os.go index 5e5d23b..f9a290e 100644 --- a/system/os.go +++ b/system/os.go @@ -51,7 +51,7 @@ func CompareOsEnv(key, comparedEnv string) bool { } // ExecCommand use shell /bin/bash -c to execute command -func ExecCommand(command string) (err error, stdout, stderr string) { +func ExecCommand(command string) (stdout, stderr string, err error) { var out bytes.Buffer var errout bytes.Buffer diff --git a/system/os_test.go b/system/os_test.go index 4126d70..6e04008 100644 --- a/system/os_test.go +++ b/system/os_test.go @@ -23,10 +23,12 @@ func TestOsEnvOperation(t *testing.T) { func TestExecCommand(t *testing.T) { assert := internal.NewAssert(t, "TestExecCommand") - err, out, errout := ExecCommand("ls") + out, errout, err := ExecCommand("ls") + t.Log("std out: ", out) + t.Log("std err: ", errout) assert.IsNil(err) - err, out, errout = ExecCommand("abc") + out, errout, err = ExecCommand("abc") t.Log("std out: ", out) t.Log("std err: ", errout) if err != nil { diff --git a/validator/validator.go b/validator/validator.go index bd1e1b8..bb1b8bd 100644 --- a/validator/validator.go +++ b/validator/validator.go @@ -67,7 +67,7 @@ func ContainLetter(str string) bool { return containLetterRegexMatcher.MatchString(str) } -// Is checks if the string is valid JSON +// IsJSON checks if the string is valid JSON func IsJSON(str string) bool { var js json.RawMessage return json.Unmarshal([]byte(str), &js) == nil