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用simulink求解一个二阶微分方程,要求截图
  • ¥30 matlab解优化问题代码
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp
  • ¥15 学不会递归,理解不了汉诺塔参数变化
  • ¥15 基于图神经网络的COVID-19药物筛选研究
  • ¥30 软件自定义无线电该怎样使用
  • ¥15 R语言mediation包做中介分析,直接效应和间接效应都很小,为什么?