Skip to content

Commit

Permalink
dynamodb: add alternative to Integer conversion helper, Int64, that d…
Browse files Browse the repository at this point in the history
…oes not silently cast float values (#459)
  • Loading branch information
bmoffatt authored Jul 27, 2022
1 parent 077490b commit d8bb932
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion events/attributevalue.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ func (av DynamoDBAttributeValue) Number() string {
return av.value.(string)
}

// Int64 provides access to an attribute of type Number.
// DynamoDB sends the values as strings. For convenience this method
// provides conversion to int.
// Method panics if the attribute is not of type Number.
func (av DynamoDBAttributeValue) Int64() (int64, error) {
number := av.Number()
return strconv.ParseInt(number, 10, 64)
}

// Integer provides access to an attribute of type Number.
// DynamoDB sends the values as strings. For convenience this method
// provides conversion to int. If the value cannot be represented by
Expand All @@ -76,7 +85,7 @@ func (av DynamoDBAttributeValue) Number() string {
// Method panics if the attribute is not of type Number.
func (av DynamoDBAttributeValue) Integer() (int64, error) {
number := av.Number()
value, err := strconv.ParseInt(number, 10, 64)
value, err := av.Int64()
if err == nil {
return value, nil
}
Expand Down

0 comments on commit d8bb932

Please sign in to comment.