mirror of
https://github.com/usememos/memos.git
synced 2025-03-31 02:50:17 +02:00
chore: fix id converter
This commit is contained in:
parent
2b7d7c95a5
commit
480c53d7a2
@ -2,10 +2,11 @@ package v2
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
|
"github.com/usememos/memos/internal/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -38,9 +39,9 @@ func GetInboxID(name string) (int32, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
id, err := strconv.Atoi(tokens[0])
|
id, err := util.ConvertStringToInt32(tokens[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, errors.Errorf("invalid inbox ID %q", tokens[0])
|
return 0, errors.Errorf("invalid inbox ID %q", tokens[0])
|
||||||
}
|
}
|
||||||
return int32(id), nil
|
return id, nil
|
||||||
}
|
}
|
||||||
|
@ -12,11 +12,11 @@ import (
|
|||||||
|
|
||||||
// ConvertStringToInt32 converts a string to int32.
|
// ConvertStringToInt32 converts a string to int32.
|
||||||
func ConvertStringToInt32(src string) (int32, error) {
|
func ConvertStringToInt32(src string) (int32, error) {
|
||||||
i, err := strconv.Atoi(src)
|
parsed, err := strconv.ParseInt(src, 10, 32)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
return int32(i), nil
|
return int32(parsed), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasPrefixes returns true if the string s has any of the given prefixes.
|
// HasPrefixes returns true if the string s has any of the given prefixes.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user