Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
章鱼 committed Nov 4, 2024
1 parent 96e9a92 commit 1e7720a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 36 deletions.
31 changes: 13 additions & 18 deletions util/conv.go
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)
}
18 changes: 0 additions & 18 deletions util/string.go

This file was deleted.

0 comments on commit 1e7720a

Please sign in to comment.