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 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了