当我尝试使用UnmarshalMap方法赋值我的结构时,我得到了以下错误:cannot use dynamodbattribute.UnmarshalMap(result.Item, &item) (type error) as type Item in assignment。
我在这里从DynamoDB表中获取项目
result, err := svc.GetItem(&dynamodb.GetItemInput{
TableName: aws.String(tableName),
Key: map[string]*dynamodb.AttributeValue{
"ForumName": {
S: aws.String(forumName),
},
},
})并获取以下JSON响应体
{
"Item":{
"Threads":{
"N":"30"
},
"Category":{
"S":"Amazon Web Services"
},
"Messages":{
"N":"11"
},
"Views":{
"N":"99"
},
"ForumName":{
"S":"AWS Step Functions"
}
}
}现在,当我尝试将我的结构
type Item struct {
ForumName string `dynamodbav:"ForumName,stringset"`
Category string `dynamodbav:"Category,stringset"`
Messages int `dynamodbav:"Messages,numberset"`
Threads int `dynamodbav:"Threads,numberset"`
Views int `dynamodbav:"Views,numberset"`
}
var item Item
item = dynamodbattribute.UnmarshalMap(result.Item, &item)我在这里得到了错误item = dynamodbattribute.UnmarshalMap(result.Item, &item)
我还尝试像这样设置我的结构
type Item struct {
ForumName string
Category string
Messages int
Threads int
Views int
}发布于 2021-10-22 07:48:41
正如Cerise Limón所说,尝试正确地处理错误,因为您正在将来自dynamodbattribute.UnmarshalMap的类型error放入预定义的项目类型变量中。所以它不会编译。
https://stackoverflow.com/questions/69654309
复制相似问题