Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
OddCN opened this issue Apr 14, 2018 · 4 comments
Open

Comments

@OddCN
Copy link
Contributor

OddCN commented Apr 14, 2018

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

  • 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
@shlokgilda
Copy link
Contributor

I second this suggestion.

@PratikDhanave
Copy link
Member

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

@PratikDhanave
Copy link
Member

+1

@OddCN
Copy link
Contributor Author

OddCN commented Apr 16, 2018

@PratikDhanave That's great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants