Last active
August 29, 2015 14:06
-
-
Save mmcgrana/f61a666c3a4288645a66 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main; | |
import ( | |
"bytes" | |
"encoding/xml" | |
"fmt" | |
) | |
var ResponseExample = ` | |
<DescribeInstanceHealthResponse xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/"> | |
<DescribeInstanceHealthResult> | |
<InstanceStates> | |
<member> | |
<Description>N/A</Description> | |
<InstanceId>i-5e96b053</InstanceId> | |
<State>InService</State> | |
<ReasonCode>N/A</ReasonCode> | |
</member> | |
<member> | |
<Description>N/A</Description> | |
<InstanceId>i-c5f1ddce</InstanceId> | |
<State>InService</State> | |
<ReasonCode>N/A</ReasonCode> | |
</member> | |
<member> | |
<Description>N/A</Description> | |
<InstanceId>i-e1f7dbea</InstanceId> | |
<State>InService</State> | |
<ReasonCode>N/A</ReasonCode> | |
</member> | |
</InstanceStates> | |
</DescribeInstanceHealthResult> | |
<ResponseMetadata> | |
<RequestId>ca6e49db-353d-11e4-92c6-f3a5ea1ffeb7</RequestId> | |
</ResponseMetadata> | |
</DescribeInstanceHealthResponse>` | |
// This structs result in only 1 InstanceState being parsed out from the | |
// response body above. | |
// type InstanceState struct { | |
// InstanceId string `xml:"member>InstanceId"` | |
// Description string `xml:"member>Description"` | |
// State string `xml:"member>State"` | |
// ReasonCode string `xml:"member>ReasonCode"` | |
// } | |
// type DescribeInstanceHealthResp struct { | |
// InstanceStates []InstanceState `xml:"DescribeInstanceHealthResult>InstanceStates"` | |
// RequestId string `xml:"ResponseMetadata>RequestId"` | |
// } | |
// These structs lead to correctly parsing out multiple InstanceStates | |
// for the response above. | |
type InstanceState struct { | |
InstanceId string `xml:"InstanceId"` | |
Description string `xml:"Description"` | |
State string `xml:"State"` | |
ReasonCode string `xml:"ReasonCode"` | |
} | |
type DescribeInstanceHealthResp struct { | |
InstanceStates []InstanceState `xml:"DescribeInstanceHealthResult>InstanceStates>member"` | |
RequestId string `xml:"ResponseMetadata>RequestId"` | |
} | |
func main() { | |
reader := bytes.NewBufferString(ResponseExample) | |
decoder := xml.NewDecoder(reader) | |
resp := &DescribeInstanceHealthResp{} | |
err := decoder.Decode(resp) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Printf("%+v\n", resp) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment