From 480c53d7a2f0a9b4c708ddf75829b271911800a6 Mon Sep 17 00:00:00 2001 From: Steven Date: Sat, 28 Oct 2023 09:04:32 +0800 Subject: [PATCH] chore: fix id converter --- api/v2/resource_name.go | 7 ++++--- internal/util/util.go | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/api/v2/resource_name.go b/api/v2/resource_name.go index 21e903cb..a12231f5 100644 --- a/api/v2/resource_name.go +++ b/api/v2/resource_name.go @@ -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 } diff --git a/internal/util/util.go b/internal/util/util.go index 96d2fde8..002789d6 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -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.