GoCloud Ali-cloud : parse response of request

Ali-cloud parse response : compute, dns, storage, loadbalancer module

odd cn
gocloud
1 min readJul 29, 2018

--

Work

  • implemented parsing response for Ali-cloud
  • updated the way of parsing response
  • unit tests

How users use

users can use code below, to parse the result of AttachLoadBalancer()

resp, err := alilb.AttachNodeWithLoadBalancer(attach)
if err != nil {
fmt.Println(err)
return
}
attachLoadBalancerResp, err := ParseAttachLoadBalancerResp(resp)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(attachLoadBalancerResp.StatusCode)
fmt.Println(attachLoadBalancerResp.LoadBalancerId)

node1 := attachLoadBalancerResp.BackendServers.BackendServer[0]

fmt.Println(node1.ServerId)
fmt.Println(node1.Weight)
fmt.Println(node1.Type)

We add the StatusCode into Resp struct

before

resp, err := alilb.AttachNodeWithLoadBalancer(attach)response := resp.(map[string]interface{})fmt.Println(response["status"])attachLoadBalancerResp, err := ParseAttachLoadBalancerResp(response["body"])

now

resp, err := alilb.AttachNodeWithLoadBalancer(attach)attachLoadBalancerResp, err := ParseAttachLoadBalancerResp(resp)fmt.Println(attachLoadBalancerResp.StatusCode)

Functions implemented

  • ParseCreateNodeResp()
  • ParseListDnsResp()
  • ParseCreateDiskResp()
  • ParseCreateLoadBalancerResp()
  • ParseAttachLoadBalancerResp()
  • ParseDetachLoadBalancerResp()

--

--