Refactor StringsToInt64s (#29967)

And close #27176
This commit is contained in:
wxiaoguang 2024-03-21 23:07:35 +08:00 committed by GitHub
parent 82979588f4
commit cdb4d1a8db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 30 additions and 27 deletions

View file

@ -150,13 +150,16 @@ func TruncateString(str string, limit int) string {
// StringsToInt64s converts a slice of string to a slice of int64.
func StringsToInt64s(strs []string) ([]int64, error) {
ints := make([]int64, len(strs))
for i := range strs {
n, err := strconv.ParseInt(strs[i], 10, 64)
if strs == nil {
return nil, nil
}
ints := make([]int64, 0, len(strs))
for _, s := range strs {
n, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return ints, err
return nil, err
}
ints[i] = n
ints = append(ints, n)
}
return ints, nil
}