chore: fix id converter

This commit is contained in:
Steven 2023-10-28 09:04:32 +08:00
parent 2b7d7c95a5
commit 480c53d7a2
2 changed files with 6 additions and 5 deletions

View File

@ -2,10 +2,11 @@ package v2
import (
"fmt"
"strconv"
"strings"
"github.com/pkg/errors"
"github.com/usememos/memos/internal/util"
)
const (
@ -38,9 +39,9 @@ func GetInboxID(name string) (int32, error) {
if err != nil {
return 0, err
}
id, err := strconv.Atoi(tokens[0])
id, err := util.ConvertStringToInt32(tokens[0])
if err != nil {
return 0, errors.Errorf("invalid inbox ID %q", tokens[0])
}
return int32(id), nil
return id, nil
}

View File

@ -12,11 +12,11 @@ import (
// ConvertStringToInt32 converts a string to int32.
func ConvertStringToInt32(src string) (int32, error) {
i, err := strconv.Atoi(src)
parsed, err := strconv.ParseInt(src, 10, 32)
if err != nil {
return 0, err
}
return int32(i), nil
return int32(parsed), nil
}
// HasPrefixes returns true if the string s has any of the given prefixes.