leopardslab / gocloud

☁️ Go API for open cloud
Apache License 2.0
119 stars 142 forks source link

Suggestion: Use Builder pattern for inputting parameters of Ali-cloud #78

Open OddCN opened 6 years ago

OddCN commented 6 years ago

For example, the current way to create a new node of Ali-cloud is:

    alicloud, _ := gocloud.CloudProvider(gocloud.Aliprovider)
    create := map[string]interface{}{
        "RegionId":            "cn-qingdao",
        "ImageId":             "centos_7_04_64_20G_alibase_201701015.vhd",
        "InstanceType":        "ecs.xn4.small",
        "SecurityGroupId":     "sg-m5egbo9s5xb21kpu6nk2",
    }
    resp, err := alicloud.Createnode(create)

The Problem

In the current way, we cannot prevent user from entering wrong parameter name and missing required parameters.

Suggestion

If we use Builder pattern like this:

    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)

We can

shlokgilda commented 6 years ago

I second this suggestion.

PratikDhanave commented 6 years ago

this is good suggestion one we cover all cloud providers we can do this in gocloud 2.0

PratikDhanave commented 6 years ago

+1

OddCN commented 6 years ago

@PratikDhanave That's great!