1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-04 12:52:28 +08:00

fix: os.go/ExecCommand make error the last return value

This commit is contained in:
dudaodong
2022-01-17 16:57:38 +08:00
parent 764a6fe107
commit 261370e30d
6 changed files with 12 additions and 8 deletions

View File

@@ -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

View File

@@ -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验证器包

View File

@@ -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

View File

@@ -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

View File

@@ -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 {

View File

@@ -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