Last active
April 27, 2018 15:09
-
-
Save OddCN/7435abb5645c1999aaa635aa28ef099e to your computer and use it in GitHub Desktop.
the 1st way we can code
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 ecs | |
import ( | |
"errors" | |
) | |
const errCommon = "ali-cloud create node miss required parameter: " | |
type CreateNode struct { | |
RegionID string //required | |
ImageID string //required | |
InstanceType string //required | |
SecurityGroupID string //required | |
ZoneID string //not necessary | |
InstanceName string //not necessary | |
Description string //not necessary | |
InternetChargeType string //not necessary | |
InternetMaxBandwidthIn int //not necessary | |
InternetMaxBandwidthOut int //not necessary | |
HostName string //not necessary | |
Password string //not necessary | |
IoOptimized string //not necessary | |
SystemDiskCategory string //not necessary | |
SystemDiskSize string //not necessary | |
SystemDiskName string //not necessary | |
SystemDiskDescription string //not necessary | |
} | |
type CreateNodeBuilder struct { | |
params *CreateNode | |
} | |
func NewCreateNodeBuilder() *CreateNodeBuilder { | |
return &CreateNodeBuilder{} | |
} | |
func (b *CreateNodeBuilder) RegionID(regionID string) *CreateNodeBuilder { | |
b.params.RegionID = regionID | |
return b | |
} | |
func (b *CreateNodeBuilder) ImageID(imageID string) *CreateNodeBuilder { | |
b.params.ImageID = imageID | |
return b | |
} | |
func (b *CreateNodeBuilder) InstanceType(instanceType string) *CreateNodeBuilder { | |
b.params.InstanceType = instanceType | |
return b | |
} | |
func (b *CreateNodeBuilder) SecurityGroupID(securityGroupID string) *CreateNodeBuilder { | |
b.params.SecurityGroupID = securityGroupID | |
return b | |
} | |
func (b *CreateNodeBuilder) ZoneID(zoneID string) *CreateNodeBuilder { | |
b.params.ZoneID = zoneID | |
return b | |
} | |
//func | |
//. | |
//. | |
//. | |
//func | |
func (b *CreateNodeBuilder) Build() (*CreateNode, error) { | |
if b.params.RegionID == "" { | |
return nil, errors.New(errCommon + "RegionID") | |
} | |
if b.params.ImageID == "" { | |
return nil, errors.New(errCommon + "ImageID") | |
} | |
if b.params.InstanceType == "" { | |
return nil, errors.New(errCommon + "InstanceType") | |
} | |
if b.params.SecurityGroupID == "" { | |
return nil, errors.New(errCommon + "SecurityGroupID") | |
} | |
return b.params, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment