Improve error handling in GenerateIdForNewUser()

This commit is contained in:
Yang Luo
2023-12-14 10:11:06 +08:00
parent 85b86e8831
commit 5c103e8cd3
2 changed files with 17 additions and 1 deletions

View File

@ -45,6 +45,19 @@ func ParseInt(s string) int {
return i
}
func ParseIntWithError(s string) (int, error) {
if s == "" {
return 0, fmt.Errorf("ParseIntWithError() error, empty string")
}
i, err := strconv.Atoi(s)
if err != nil {
return 0, err
}
return i, nil
}
func ParseFloat(s string) float64 {
f, err := strconv.ParseFloat(s, 64)
if err != nil {