Files
mayfly-go/server/pkg/utils/stringx/conv.go
2024-01-15 20:51:41 +08:00

18 lines
322 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 stringx
import (
"strconv"
)
// 将字符串值转为int值, 若value为空或者转换失败则返回默认值
func ConvInt(value string, defaultValue int) int {
if value == "" {
return defaultValue
}
if intV, err := strconv.Atoi(value); err != nil {
return defaultValue
} else {
return intV
}
}