douting1871 2018-10-08 02:55
浏览 20

如何测试从AWS开发工具包找不到的结果?

I am a beginner in Go and am starting to use the AWS SDK.

I want to fetch some EC2 fields by looking for a tag using DescribeInstances. That works well. But if I use a tag that does not exist as parameter I get an empty struct as response:

{

}

I tried to test the result with nil and using unsafe.Sizeof(), but I don't get nil value or 0 value. What would be the correct way to do it? Thanks!

edit: I found a way to check. Because the aws api is inconsistent, sometimes it returns errors sometimes it does not. So for this sparticular call I test the size of the []*ec2.Reservation that is returned:

result, err := ec2Svc.DescribeInstances(input)
if len(result.Reservations) == 0 {
  fmt.Println("Nothing found for this tag")
  fmt.Println(err)
} else {
  for _, instance := range result.Reservations[0].Instances {
    return *instance.VpcId
  }
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 个人网站被恶意大量访问,怎么办
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)