doulaopu2343 2019-05-06 07:37 采纳率: 100%
浏览 22

反序列化AWS结构到字符串映射

I'm trying to deserialise an aws struct in go so that I can pass in parameters and output values based on those parameters, for example;

   12 func DisplayResults(conf *config.Configuration,
           regionalData []*ec2.DescribeInstancesOutput) {

   13   log.Debug("Displaying results")
   14   log.Debug("Table view [%v]", conf.Display)
   15     
   16   for _, rv := range regionalData {
   17     for _, reservation := range rv.Reservations {
   18       for _, instance := range reservation.Instances {
   19         var i map[string]interface{}                                                                                                                                                                          
   20         json.Unmarshal(instance, i)
   21       }
   22     }
   23   }
   24 }

I've also tried using:

"github.com/fatih/structs"
   18         i := structs.Map(instance)                                                                                                                                                                        
   19         log.Print("%v", i)

however, I think that I need to somehow derefence the struct because my output looks like this:

RamdiskId:<nil> SriovNetSupport:<nil> VpcId:0xc420321ba0 State:map[Code:0xc42031ea08 Name:0xc420321890] VirtualizationType:0xc420321b90 CapacityReservationId:<nil> ClientToken:0xc420321560 HibernationOptions:map[Configured:0xc42031e96b] IamInstanceProfile:map[Arn:0xc4203215a0 Id:0xc4203215b0] ImageId:0xc4203215c0

I've also tried this:

~  10 func DisplayResults(conf *config.Configuration, regionalData []*ec2.DescribeInstancesOutput, parameters []string) {                                                                                       
   11   log.Debug("Displaying results")
   12   log.Debug("Table view [%v]", conf.Display)
   13 
   14   for _, rv := range regionalData {
   15     for _, reservation := range rv.Reservations {
   16       for _, instance := range reservation.Instances {
~  17         y := deref(instance)
~  18 
+  19         log.Print("%v", y["InstanceId"])
   20       }
   21     } 
   22   } 
   23 } 
   24 
~  25 func deref(instance *ec2.Instance) ec2.Instance {
~  26   var i ec2.Instance
   27   
~  28   x := &i
+  29   *x = *instance
   30   
~  31   return i
   32 } 
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测