dph87312 2018-04-20 17:55 采纳率: 100%
浏览 16
已采纳

aws-sdk-go dynamodbattribute取消编组的地图未编组的列表

I have a Dynamodb Table that has the following struct:

type StatusItem struct {
    requestStatus string
    timestamp string
    RequestId string
}

I have the code as such:

items := []StatusItem{}
err = dynamodbattribute.UnmarshalListOfMaps(result.Items, &items)
if err != nil {
    exitWithError(fmt.Errorf("failed to unmarshal Query result items, %v", err))
}

// Print out the items returned
for i, item := range items {
    fmt.Println(i)
    fmt.Printf(item.RequestId, item.requestStatus)
}

However, items is empty.

when i put a watcher in items, i can see the it unmarshals to the struct, but all the values are empty.

if i do: log.println(result.items) i can see the values there (though a bit ugly)

%!(EXTRA string=)[map[timestamp:{
  S: "2018-04-18 12:04:43.761"
} RequestId:{
  S: "9"
} requestStatus:{
  S: "REQUEST_RECEIVED"
}]

what am i doing wrong?

  • 写回答

1条回答 默认 最新

  • dt888999 2018-04-20 19:56
    关注

    Thanks to @Peter for pointing me in the right direction.

    The solution is simple (though rather dumb that that was the case).

    as noted in : https://til.hashrocket.com/posts/3512417fb0-private-vs-public-struct-members

    lowercase starting members are private, and Capital was public.

    in order to get it working correctly, i needed to update my struct from:

    type StatusItem struct {
        requestStatus string
        timestamp string
        RequestId string
    }
    

    to:

    type StatusItem struct {
        RequestStatus string
        Timestamp string
        RequestId string
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab提取运动物体的坐标
  • ¥15 人大金仓下载,有人知道怎么解决吗
  • ¥15 一个小问题,本人刚入门,哪位可以help
  • ¥15 python安卓开发
  • ¥15 使用R语言GD包一直不出结果
  • ¥15 计算机微处理器与接口技术相关问题,求解答图片的这个问题,有多少个端口,端口地址和解答问题的方法和思路,不要AI作答
  • ¥15 如何根据一个截图编写对应的HTML代码
  • ¥15 stm32标准库的PID角度环
  • ¥15 ADS已经下载好了,但是DAS下载不了,一直显示这两种情况,有什么办法吗,非常急!
  • ¥100 Excel 点击发送自动跳转outlook邮件