GoCloud work summary
Ali-cloud, Vultr, modular, builder pattern, parsing response
In GSoC 2018, I implemented Ali-cloud and Vultr support for GoCloud. And other works: GoCloud modular, builder pattern for inputting, parsing response.
Ali-cloud and Vultr support
Ali-cloud modules implemented:
- ECS Compute
- ECS Storage
- Alibaba Cloud DNS
- Server Load Balancer
- Container Service
Vultr modules implemented:
- Server
- Bare Metal
- Block Storage
- DNS
For every implementation of modules and functions, contains unit tests, API documentations, example documentations and getting start tutorial video.
GoCloud modular
Achieved three goals:
- way to call: GoCloud.<ServiceType>.<Functionality>
- development scalable
- ensure the API is uniform like before
Implemented the way to call like this
gocloud.AmazonProvider().MachineLearning().CreateMLModel()
More information about GoCloud modular
Builder pattern for inputting parameters
Achieved four goals:
- Prevent user from inputting wrong parameter name
- Throw an error when user miss input required parameters
- Let user add parameters in different places
- Let user have higher freedom, clearer code
Code of using builder pattern for inputting parameters:
alicloud, _ := gocloud.CloudProvider(gocloud.Aliprovider)
createNodeBuilder := ecs.NewCreateNodeBuilder().
RegionID("cn-qingdao").
ImageID("centos_7_04_64_20G_alibase_201701015.vhd").
InstanceType("ecs.xn4.small").
SecurityGroupID("sg-m5egbo9s5xb21kpu6nk2")
createNode, err := createNodeBuilder.Build()
if err != nil {
// May miss required parameters
}
resp, err := alicloud.Createnode(createNode)
Ali-cloud and Vultr are support builder pattern input now.
More information about Builder pattern for inputting parameters
Parsing response
Achieved two goals:
- users get the response struct directly
- put HTTP/HTTPS status code into response struct
Code of parsing response of AttachNodeWithLoadBalancer():
resp, err := alilb.AttachNodeWithLoadBalancer(attach)
if err != nil {
fmt.Println(err)
return
}attachLBResp, err := alilb.ParseAttachLoadBalancerResp(resp)
if err != nil {
fmt.Println(err)
return
}if attachLBResp.StatusCode == 200 { fmt.Println(attachLBResp.LoadBalancerId)
node1 := attachLBResp.BackendServers.BackendServer[0]
fmt.Println(node1.ServerId)
fmt.Println(node1.Weight)
fmt.Println(node1.Type)}
For Ali-cloud, functions implemented:
- ParseCreateNodeResp()
- ParseCreateClusterResp()
- ParseListDnsResp()
- ParseCreateDiskResp()
- ParseCreateLoadBalancerResp()
- ParseAttachLoadBalancerResp()
- ParseDetachLoadBalancerResp()
For Vultr, functions implemented:
- ParseListDnsResp()
- ParseCreateDiskResp()
- ParseCreateNodeResp()
- ParseCreateBareMetalResp()
- ParseListBareMetalResp()