-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
章鱼
committed
Nov 4, 2024
1 parent
96e9a92
commit 1e7720a
Showing
2 changed files
with
13 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,47 @@ | ||
package util | ||
|
||
import ( | ||
"github.com/gookit/goutil/mathutil" | ||
"github.com/gookit/goutil/strutil" | ||
"github.com/spf13/cast" | ||
) | ||
|
||
// Bool convert value to bool | ||
|
||
// String always convert value to string, will ignore error | ||
func String(v any) string { | ||
s, _ := strutil.AnyToString(v, false) | ||
return s | ||
return ToString(v) | ||
} | ||
|
||
// ToString convert value to string, will return error on fail. | ||
func ToString(v any) (string, error) { | ||
return strutil.AnyToString(v, true) | ||
func ToString(v any) string { | ||
return cast.ToString(v) | ||
} | ||
|
||
// Int convert value to int | ||
func Int(v any) int { | ||
iv, _ := mathutil.ToInt(v) | ||
return iv | ||
return cast.ToInt(v) | ||
} | ||
|
||
// ToInt try to convert value to int | ||
func ToInt(v any) (int, error) { | ||
return mathutil.ToInt(v) | ||
func ToInt(v any) int { | ||
return cast.ToInt(v) | ||
} | ||
|
||
// Int64 convert value to int64 | ||
func Int64(v any) int64 { | ||
iv, _ := mathutil.ToInt64(v) | ||
return iv | ||
return cast.ToInt64(v) | ||
} | ||
|
||
// ToInt64 try to convert value to int64 | ||
func ToInt64(v any) (int64, error) { | ||
return mathutil.ToInt64(v) | ||
func ToInt64(v any) int64 { | ||
return cast.ToInt64(v) | ||
} | ||
|
||
// Uint convert value to uint64 | ||
func Uint(v any) uint64 { | ||
iv, _ := mathutil.ToUint(v) | ||
return iv | ||
return cast.ToUint64(v) | ||
} | ||
|
||
// ToUint try to convert value to uint64 | ||
func ToUint(v any) (uint64, error) { | ||
return mathutil.ToUint(v) | ||
func ToUint(v any) uint64 { | ||
return cast.ToUint64(v) | ||
} |
This file was deleted.
Oops, something went wrong.