Skip to content

Commit

Permalink
✨ up(math): add new util func SafeInt64
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Mar 4, 2023
1 parent 5036234 commit 39019ad
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/comfunc/sysfunc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions mathutil/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions mathutil/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down

0 comments on commit 39019ad

Please sign in to comment.