diff --git a/helper/strings/strings.go b/helper/strings/strings.go index 3df5779..51f30b5 100644 --- a/helper/strings/strings.go +++ b/helper/strings/strings.go @@ -32,6 +32,17 @@ func ToInteger[T constraints.Integer](s string, defaults T) T { } return T(i) } +func ToInt[T constraints.Integer](s string) T { + defaults := T(0) + if s == "" { + return defaults + } + i, err := strconv.ParseInt(s, 10, 64) + if err != nil { + return defaults + } + return T(i) +} func Md5(str string) string { h := md5.New()