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:
@@ -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 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 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 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
|
### 13. validator is for data validation
|
||||||
|
|||||||
@@ -536,7 +536,7 @@ func GetOsEnv(key string) string //获取名称为key的环境变量
|
|||||||
func SetOsEnv(key, value string) error //设置环境变量
|
func SetOsEnv(key, value string) error //设置环境变量
|
||||||
func RemoveOsEnv(key string) error //删除指定key的环境变量
|
func RemoveOsEnv(key string) error //删除指定key的环境变量
|
||||||
func CompareOsEnv(key, comparedEnv string) bool //获取名称为key的环境变量并和comparedEnv比较
|
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验证器包
|
### 13. validator验证器包
|
||||||
|
|||||||
@@ -15,7 +15,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DefaultRetryTimes = 5
|
// DefaultRetryTimes times of retry
|
||||||
|
DefaultRetryTimes = 5
|
||||||
|
// DefaultRetryDuration time duration of two retries
|
||||||
DefaultRetryDuration = time.Second * 3
|
DefaultRetryDuration = time.Second * 3
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -26,7 +28,7 @@ type RetryConfig struct {
|
|||||||
retryDuration time.Duration
|
retryDuration time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// RetryFn is function that retry executes
|
// RetryFunc is function that retry executes
|
||||||
type RetryFunc func() error
|
type RetryFunc func() error
|
||||||
|
|
||||||
// Option is for adding retry config
|
// Option is for adding retry config
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ func CompareOsEnv(key, comparedEnv string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ExecCommand use shell /bin/bash -c to execute command
|
// 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 out bytes.Buffer
|
||||||
var errout bytes.Buffer
|
var errout bytes.Buffer
|
||||||
|
|
||||||
|
|||||||
@@ -23,10 +23,12 @@ func TestOsEnvOperation(t *testing.T) {
|
|||||||
func TestExecCommand(t *testing.T) {
|
func TestExecCommand(t *testing.T) {
|
||||||
assert := internal.NewAssert(t, "TestExecCommand")
|
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)
|
assert.IsNil(err)
|
||||||
|
|
||||||
err, out, errout = ExecCommand("abc")
|
out, errout, err = ExecCommand("abc")
|
||||||
t.Log("std out: ", out)
|
t.Log("std out: ", out)
|
||||||
t.Log("std err: ", errout)
|
t.Log("std err: ", errout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ func ContainLetter(str string) bool {
|
|||||||
return containLetterRegexMatcher.MatchString(str)
|
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 {
|
func IsJSON(str string) bool {
|
||||||
var js json.RawMessage
|
var js json.RawMessage
|
||||||
return json.Unmarshal([]byte(str), &js) == nil
|
return json.Unmarshal([]byte(str), &js) == nil
|
||||||
|
|||||||
Reference in New Issue
Block a user