go - 如何使用 aws sdk go v2 初始化 PutItemInput 结构以在 DynamoDb 上执行 PutItem 而不会出现此错误?
问题描述
当我尝试使用aws go sdk v2初始化输入变量以在 DynamoDB 表上执行 PutItem 时,它给了我一个错误 - 在复合文字中缺少类型。我在这里查看了结构 PutItemInput - https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/dynamodb@v1.2.2#PutItemInput我不明白如何摆脱这个错误?id 是 mytable 中的分区键
input := &dynamodb.PutItemInput{
TableName: aws.String("mytable"),
Item: map[string]types.AttributeValue{
"id": {
N: aws.String(a.ID),
},
},
}
解决方案
Item: map[string]types.AttributeValue{
"id": &types.AttributeValueMemberN{a.ID},
}
types.AttributeValue
is an interface type. When constructing maps or slices of interfaces you cannot elide the concrete type of the individual elements from the composite literal. You need to tell the compiler what concrete type you would like an element to have.
推荐阅读
- c++ - C++ Curl 无法使用 SSL_CTX_FUNCTION 的 LetsEncrypt pem 文件进行连接
- java - 如何在 j00q 中引用 Postgres 约束?
- mongodb - 如何在 ubuntu 15.10 上安装 Mongodb 4
- python - Python 中的效率:a = array[x][y] vs array[x][y]
- binary - 八度四舍五入和评估顺序
- excel - VBA PivotTable 和 PivotField - PivotField.CurrentPage 未更新
- c++ - boost::program_options: 是否可以将一个选项设置为另一个选项的默认值?
- php - 未定义的属性:stdClass - LARAVEL
- php - 如何修复(Curl PHP)中不允许的 405
- asp.net - 如何防止 Owin 在会话到期时重定向到登录?