Files
mayfly-go/server/pkg/utils/conv/string.go
2024-01-18 17:18:17 +08:00

20 lines
388 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package conv
import (
"mayfly-go/pkg/logx"
"strconv"
)
// 将字符串值转为int值, 若value为空或者转换失败则返回默认值
func Str2Int(value string, defaultValue int) int {
if value == "" {
return defaultValue
}
if intV, err := strconv.Atoi(value); err != nil {
logx.ErrorTrace("str conv int error: ", err)
return defaultValue
} else {
return intV
}
}