diff --git a/internal/comfunc/sysfunc.go b/internal/comfunc/sysfunc.go index a78296717..76fd61f4c 100644 --- a/internal/comfunc/sysfunc.go +++ b/internal/comfunc/sysfunc.go @@ -47,7 +47,7 @@ func ExecCmd(binName string, args []string, workDir ...string) (string, error) { } // ShellExec exec command by shell -// cmdLine eg. "ls -al" +// cmdLine e.g. "ls -al" func ShellExec(cmdLine string, shells ...string) (string, error) { // shell := "/bin/sh" shell := "sh" diff --git a/mathutil/convert.go b/mathutil/convert.go index b6a9bfcea..c8bf85519 100644 --- a/mathutil/convert.go +++ b/mathutil/convert.go @@ -172,6 +172,12 @@ func Int64(in any) (int64, error) { return ToInt64(in) } +// SafeInt64 convert value to int64, will ignore error +func SafeInt64(in any) int64 { + i64, _ := ToInt64(in) + return i64 +} + // QuietInt64 convert value to int64, will ignore error func QuietInt64(in any) int64 { i64, _ := ToInt64(in) diff --git a/mathutil/convert_test.go b/mathutil/convert_test.go index 684a2ee1c..c8aea30e6 100644 --- a/mathutil/convert_test.go +++ b/mathutil/convert_test.go @@ -91,6 +91,7 @@ func TestToInt(t *testing.T) { for _, in := range errTests { is.Eq(int64(0), mathutil.MustInt64(in)) is.Eq(int64(0), mathutil.QuietInt64(in)) + is.Eq(int64(0), mathutil.SafeInt64(in)) } }