Skip to content

Commit 46ca97c

Browse files
committed
dynamodb: add alternative to Integer conversion helper, Int64, that does not silently cast float values
1 parent 6796528 commit 46ca97c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

events/attributevalue.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ func (av DynamoDBAttributeValue) Number() string {
6868
return av.value.(string)
6969
}
7070

71+
// Int64 provides access to an attribute of type Number.
72+
// DynamoDB sends the values as strings. For convenience this method
73+
// provides conversion to int.
74+
// Method panics if the attribute is not of type Number.
75+
func (av DynamoDBAttributeValue) Int64() (int64, error) {
76+
number := av.Number()
77+
return strconv.ParseInt(number, 10, 64)
78+
}
79+
7180
// Integer provides access to an attribute of type Number.
7281
// DynamoDB sends the values as strings. For convenience this method
7382
// provides conversion to int. If the value cannot be represented by
@@ -76,7 +85,7 @@ func (av DynamoDBAttributeValue) Number() string {
7685
// Method panics if the attribute is not of type Number.
7786
func (av DynamoDBAttributeValue) Integer() (int64, error) {
7887
number := av.Number()
79-
value, err := strconv.ParseInt(number, 10, 64)
88+
value, err := av.Int64()
8089
if err == nil {
8190
return value, nil
8291
}

0 commit comments

Comments
 (0)