Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dynamodb: add alternative to Integer conversion helper, Int64, that does not silently cast float values #459

Merged
merged 1 commit into from Jul 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion events/attributevalue.go
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