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 }