首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Golang aws-sdk-go dynamodb UnmarshalMap类型错误分配

Golang aws-sdk-go dynamodb UnmarshalMap类型错误分配
EN

Stack Overflow用户
提问于 2021-10-20 23:59:15
回答 1查看 173关注 0票数 0

当我尝试使用UnmarshalMap方法赋值我的结构时,我得到了以下错误:cannot use dynamodbattribute.UnmarshalMap(result.Item, &item) (type error) as type Item in assignment

我在这里从DynamoDB表中获取项目

代码语言:javascript
复制
result, err := svc.GetItem(&dynamodb.GetItemInput{
        TableName: aws.String(tableName),
        Key: map[string]*dynamodb.AttributeValue{
            "ForumName": {
                S: aws.String(forumName),
            },
        },
    })

并获取以下JSON响应体

代码语言:javascript
复制
{
   "Item":{
      "Threads":{
         "N":"30"
      },
      "Category":{
         "S":"Amazon Web Services"
      },
      "Messages":{
         "N":"11"
      },
      "Views":{
         "N":"99"
      },
      "ForumName":{
         "S":"AWS Step Functions"
      }
   }
}

现在,当我尝试将我的结构

代码语言:javascript
复制
    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)

我还尝试像这样设置我的结构

代码语言:javascript
复制
    type Item struct {
        ForumName string 
        Category  string 
        Messages  int    
        Threads   int    
        Views     int    
    }
EN

回答 1

Stack Overflow用户

发布于 2021-10-22 07:48:41

正如Cerise Limón所说,尝试正确地处理错误,因为您正在将来自dynamodbattribute.UnmarshalMap的类型error放入预定义的项目类型变量中。所以它不会编译。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69654309

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档