瀏覽代碼

fix eci flatRepeatedList error

wenzuochao 6 年之前
父節點
當前提交
e549614703

+ 78 - 58
sdk/requests/acs_request.go

@@ -332,66 +332,86 @@ func flatRepeatedList(dataValue reflect.Value, request AcsRequest, position, pre
 				}
 			} else if typeTag == "Repeated" {
 				// repeated param
-				repeatedFieldValue := dataValue.Field(i)
-				if repeatedFieldValue.Kind() != reflect.Slice {
-					// possible value: {"[]string", "*[]struct"}, we must call Elem() in the last condition
-					repeatedFieldValue = repeatedFieldValue.Elem()
+				err = handleRepeatedParams(request, dataValue, prefix, name, fieldPosition, i)
+				if err != nil {
+					return
 				}
-				if repeatedFieldValue.IsValid() && !repeatedFieldValue.IsNil() {
-					for m := 0; m < repeatedFieldValue.Len(); m++ {
-						elementValue := repeatedFieldValue.Index(m)
-						key := prefix + name + "." + strconv.Itoa(m+1)
-						if elementValue.Type().Kind().String() == "string" {
-							value := elementValue.String()
-							err = addParam(request, fieldPosition, key, value)
-							if err != nil {
-								return
-							}
-						} else {
-							err = flatRepeatedList(elementValue, request, fieldPosition, key+".")
-							if err != nil {
-								return
-							}
-						}
+			} else if typeTag == "Struct" {
+				err = handleStruct(request, dataValue, prefix, name, fieldPosition, i)
+				if err != nil {
+					return
+				}
+			}
+		}
+	}
+	return
+}
+
+func handleRepeatedParams(request AcsRequest, dataValue reflect.Value, prefix, name, fieldPosition string, index int) (err error) {
+	repeatedFieldValue := dataValue.Field(index)
+	if repeatedFieldValue.Kind() != reflect.Slice {
+		// possible value: {"[]string", "*[]struct"}, we must call Elem() in the last condition
+		repeatedFieldValue = repeatedFieldValue.Elem()
+	}
+	if repeatedFieldValue.IsValid() && !repeatedFieldValue.IsNil() {
+		for m := 0; m < repeatedFieldValue.Len(); m++ {
+			elementValue := repeatedFieldValue.Index(m)
+			key := prefix + name + "." + strconv.Itoa(m+1)
+			if elementValue.Type().Kind().String() == "string" {
+				value := elementValue.String()
+				err = addParam(request, fieldPosition, key, value)
+				if err != nil {
+					return
+				}
+			} else {
+				err = flatRepeatedList(elementValue, request, fieldPosition, key+".")
+				if err != nil {
+					return
+				}
+			}
+		}
+	}
+	return nil
+}
+
+func handleStruct(request AcsRequest, dataValue reflect.Value, prefix, name, fieldPosition string, index int) (err error) {
+	valueField := dataValue.Field(index)
+	if valueField.IsValid() && valueField.String() != "" {
+		valueFieldType := valueField.Type()
+		for m := 0; m < valueFieldType.NumField(); m++ {
+			fieldName := valueFieldType.Field(m).Name
+			elementValue := valueField.FieldByName(fieldName)
+			key := prefix + name + "." + fieldName
+			if elementValue.Type().String() == "[]string" {
+				if elementValue.IsNil() {
+					continue
+				}
+				for j := 0; j < elementValue.Len(); j++ {
+					err = addParam(request, fieldPosition, key+"."+strconv.Itoa(j+1), elementValue.Index(j).String())
+					if err != nil {
+						return
 					}
 				}
-			} else if typeTag == "Struct" {
-				valueField := dataValue.Field(i)
-				if valueField.Kind() == reflect.Struct {
-					if valueField.IsValid() && valueField.String() != "" {
-						valueFieldType := valueField.Type()
-						for m := 0; m < valueFieldType.NumField(); m++ {
-							fieldName := valueFieldType.Field(m).Name
-							elementValue := valueField.FieldByName(fieldName)
-							key := prefix + name + "." + fieldName
-							if elementValue.Type().String() == "[]string" {
-								if elementValue.IsNil() {
-									continue
-								}
-								for j := 0; j < elementValue.Len(); j++ {
-									err = addParam(request, fieldPosition, key+"."+strconv.Itoa(j+1), elementValue.Index(j).String())
-									if err != nil {
-										return
-									}
-								}
-							} else {
-								if elementValue.Type().Kind().String() == "string" {
-									value := elementValue.String()
-									err = addParam(request, fieldPosition, key, value)
-									if err != nil {
-										return
-									}
-								} else if elementValue.Type().Kind().String() == "struct" {
-									err = flatRepeatedList(elementValue, request, fieldPosition, key+".")
-									if err != nil {
-										return
-									}
-								} else if !elementValue.IsNil() {
-									err = flatRepeatedList(elementValue.Elem(), request, fieldPosition, key+".")
-									if err != nil {
-										return
-									}
-								}
+			} else {
+				if elementValue.Type().Kind().String() == "string" {
+					value := elementValue.String()
+					err = addParam(request, fieldPosition, key, value)
+					if err != nil {
+						return
+					}
+				} else if elementValue.Type().Kind().String() == "struct" {
+					err = flatRepeatedList(elementValue, request, fieldPosition, key+".")
+					if err != nil {
+						return
+					}
+				} else if !elementValue.IsNil() {
+					repeatedFieldValue := elementValue.Elem()
+					if repeatedFieldValue.IsValid() && !repeatedFieldValue.IsNil() {
+						for m := 0; m < repeatedFieldValue.Len(); m++ {
+							elementValue := repeatedFieldValue.Index(m)
+							err = flatRepeatedList(elementValue, request, fieldPosition, key+"."+strconv.Itoa(m+1)+".")
+							if err != nil {
+								return
 							}
 						}
 					}
@@ -399,7 +419,7 @@ func flatRepeatedList(dataValue reflect.Value, request AcsRequest, position, pre
 			}
 		}
 	}
-	return
+	return nil
 }
 
 func addParam(request AcsRequest, position, name, value string) (err error) {

+ 16 - 1
sdk/requests/acs_request_test.go

@@ -196,7 +196,7 @@ type CreateContainerGroupVolume struct {
 type CreateContainerGroupDnsConfig struct {
 	NameServer []string                      `name:"NameServer"`
 	Search     []string                      `name:"Search"`
-	Option     *[]CreateContainerGroupOption `name:"Option"`
+	Option     *[]CreateContainerGroupOption `name:"Option" type:"Repeated"`
 }
 
 type CreateContainerGroupNFSVolume struct {
@@ -260,6 +260,21 @@ func Test_AcsRequest_InitParams4(t *testing.T) {
 }
 
 func Test_AcsRequest_InitParams5(t *testing.T) {
+	r := InitRequest()
+	r.RegionId = "regionid"
+	r.DnsConfig = CreateContainerGroupDnsConfig{
+		Option: &[]CreateContainerGroupOption{
+			{
+				Name:  "sdk",
+				Value: "test",
+			},
+		},
+	}
+	InitParams(r)
+	assert.Equal(t, "DnsConfig.Option.1.Name=sdk&DnsConfig.Option.1.Value=test&", GetQueryString(r))
+}
+
+func Test_AcsRequest_InitParams6(t *testing.T) {
 	r := InitRequest()
 	r.Volume = &[]CreateContainerGroupVolume{
 		{

+ 13 - 6
services/eci/create_container_group.go

@@ -102,6 +102,7 @@ type CreateContainerGroupRequest struct {
 	InstanceType            string                                         `position:"Query" name:"InstanceType"`
 	SlsEnable               requests.Boolean                               `position:"Query" name:"SlsEnable"`
 	ImageSnapshotId         string                                         `position:"Query" name:"ImageSnapshotId"`
+	RamRoleName             string                                         `position:"Query" name:"RamRoleName"`
 	DnsConfig               CreateContainerGroupDnsConfig                  `position:"Query" name:"DnsConfig" type:"Struct"`
 	SecurityContext         CreateContainerGroupSecurityContext            `position:"Query" name:"SecurityContext" type:"Struct"`
 }
@@ -144,6 +145,7 @@ type CreateContainerGroupVolume struct {
 	NFSVolume        CreateContainerGroupNFSVolume        `name:"NFSVolume" type:"Struct"`
 	ConfigFileVolume CreateContainerGroupConfigFileVolume `name:"ConfigFileVolume" type:"Struct"`
 	EmptyDirVolume   CreateContainerGroupEmptyDirVolume   `name:"EmptyDirVolume" type:"Struct"`
+	DiskVolume       CreateContainerGroupDiskVolume       `name:"DiskVolume" type:"Struct"`
 }
 
 type CreateContainerGroupInitContainer struct {
@@ -174,13 +176,13 @@ type CreateContainerGroupArn struct {
 }
 
 type CreateContainerGroupDnsConfig struct {
-	NameServer []string                      `name:"NameServer"`
-	Search     []string                      `name:"Search"`
-	Option     *[]CreateContainerGroupOption `name:"Option"`
+	NameServer []string                      `name:"NameServer" type:"Repeated"`
+	Search     []string                      `name:"Search" type:"Repeated"`
+	Option     *[]CreateContainerGroupOption `name:"Option" type:"Repeated"`
 }
 
 type CreateContainerGroupSecurityContext struct {
-	Sysctl *[]CreateContainerGroupSysctl `name:"Sysctl"`
+	Sysctl *[]CreateContainerGroupSysctl `name:"Sysctl" type:"Repeated"`
 }
 
 type CreateContainerGroupVolumeMount struct {
@@ -223,7 +225,7 @@ type CreateContainerGroupHttpGet struct {
 }
 
 type CreateContainerGroupExec struct {
-	Command []string `name:"Command"`
+	Command []string `name:"Command" type:"Repeated"`
 }
 
 type CreateContainerGroupTcpSocket struct {
@@ -248,7 +250,7 @@ type CreateContainerGroupNFSVolume struct {
 }
 
 type CreateContainerGroupConfigFileVolume struct {
-	ConfigFileToPath *[]CreateContainerGroupConfigFileToPath `name:"ConfigFileToPath"`
+	ConfigFileToPath *[]CreateContainerGroupConfigFileToPath `name:"ConfigFileToPath" type:"Repeated"`
 	DefaultModel     requests.Integer                        `name:"DefaultModel"`
 }
 
@@ -262,6 +264,11 @@ type CreateContainerGroupEmptyDirVolume struct {
 	Medium string `name:"Medium"`
 }
 
+type CreateContainerGroupDiskVolume struct {
+	DiskId string `name:"DiskId"`
+	FsType string `name:"FsType"`
+}
+
 type CreateContainerGroupOption struct {
 	Name  string `name:"Name"`
 	Value string `name:"Value"`

+ 27 - 15
services/eci/describe_container_group_price.go

@@ -93,32 +93,44 @@ type DescribeContainerGroupPriceResponse struct {
 }
 
 type DescribeContainerGroupPricePriceInfo0 struct {
-	Rules []DescribeContainerGroupPriceRule1 `json:"Rules" xml:"Rules"`
-	Price DescribeContainerGroupPricePrice1  `json:"Price" xml:"Price"`
+	Rules DescribeContainerGroupPriceRules1 `json:"Rules" xml:"Rules"`
+	Price DescribeContainerGroupPricePrice1 `json:"Price" xml:"Price"`
 }
 
-type DescribeContainerGroupPriceRule1 struct {
+type DescribeContainerGroupPriceRules1 struct {
+	Rule []DescribeContainerGroupPriceRule2 `json:"Rule" xml:"Rule"`
+}
+
+type DescribeContainerGroupPriceRule2 struct {
 	RuleId      int64  `json:"RuleId" xml:"RuleId"`
 	Description string `json:"Description" xml:"Description"`
 }
 
 type DescribeContainerGroupPricePrice1 struct {
-	OriginalPrice float32                                  `json:"OriginalPrice" xml:"OriginalPrice"`
-	DiscountPrice float32                                  `json:"DiscountPrice" xml:"DiscountPrice"`
-	TradePrice    float32                                  `json:"TradePrice" xml:"TradePrice"`
-	Currency      string                                   `json:"Currency" xml:"Currency"`
-	DetailInfos   []DescribeContainerGroupPriceDetailInfo2 `json:"DetailInfos" xml:"DetailInfos"`
+	OriginalPrice float32                                 `json:"OriginalPrice" xml:"OriginalPrice"`
+	DiscountPrice float32                                 `json:"DiscountPrice" xml:"DiscountPrice"`
+	TradePrice    float32                                 `json:"TradePrice" xml:"TradePrice"`
+	Currency      string                                  `json:"Currency" xml:"Currency"`
+	DetailInfos   DescribeContainerGroupPriceDetailInfos2 `json:"DetailInfos" xml:"DetailInfos"`
+}
+
+type DescribeContainerGroupPriceDetailInfos2 struct {
+	DetailInfo []DescribeContainerGroupPriceDetailInfo3 `json:"DetailInfo" xml:"DetailInfo"`
+}
+
+type DescribeContainerGroupPriceDetailInfo3 struct {
+	Resource      string                            `json:"Resource" xml:"Resource"`
+	OriginalPrice float32                           `json:"OriginalPrice" xml:"OriginalPrice"`
+	DiscountPrice float32                           `json:"DiscountPrice" xml:"DiscountPrice"`
+	TradePrice    float32                           `json:"TradePrice" xml:"TradePrice"`
+	Rules         DescribeContainerGroupPriceRules4 `json:"Rules" xml:"Rules"`
 }
 
-type DescribeContainerGroupPriceDetailInfo2 struct {
-	Resource      string                             `json:"Resource" xml:"Resource"`
-	OriginalPrice float32                            `json:"OriginalPrice" xml:"OriginalPrice"`
-	DiscountPrice float32                            `json:"DiscountPrice" xml:"DiscountPrice"`
-	TradePrice    float32                            `json:"TradePrice" xml:"TradePrice"`
-	Rules         []DescribeContainerGroupPriceRule3 `json:"Rules" xml:"Rules"`
+type DescribeContainerGroupPriceRules4 struct {
+	Rule []DescribeContainerGroupPriceRule5 `json:"Rule" xml:"Rule"`
 }
 
-type DescribeContainerGroupPriceRule3 struct {
+type DescribeContainerGroupPriceRule5 struct {
 	RuleId      int64  `json:"RuleId" xml:"RuleId"`
 	Description string `json:"Description" xml:"Description"`
 }

+ 3 - 0
services/eci/describe_container_groups.go

@@ -124,6 +124,7 @@ type DescribeContainerGroupsContainerGroup0 struct {
 	InstanceType       string                                     `json:"InstanceType" xml:"InstanceType"`
 	ExpiredTime        string                                     `json:"ExpiredTime" xml:"ExpiredTime"`
 	FailedTime         string                                     `json:"FailedTime" xml:"FailedTime"`
+	RamRoleName        string                                     `json:"RamRoleName" xml:"RamRoleName"`
 	Tags               []DescribeContainerGroupsLabel1            `json:"Tags" xml:"Tags"`
 	Events             []DescribeContainerGroupsEvent1            `json:"Events" xml:"Events"`
 	Containers         []DescribeContainerGroupsContainer1        `json:"Containers" xml:"Containers"`
@@ -267,6 +268,8 @@ type DescribeContainerGroupsVolume1 struct {
 	NFSVolumePath                     string                                                     `json:"NFSVolumePath" xml:"NFSVolumePath"`
 	NFSVolumeServer                   string                                                     `json:"NFSVolumeServer" xml:"NFSVolumeServer"`
 	NFSVolumeReadOnly                 bool                                                       `json:"NFSVolumeReadOnly" xml:"NFSVolumeReadOnly"`
+	DiskVolumeDiskId                  string                                                     `json:"DiskVolumeDiskId" xml:"DiskVolumeDiskId"`
+	DiskVolumeFsType                  string                                                     `json:"DiskVolumeFsType" xml:"DiskVolumeFsType"`
 	ConfigFileVolumeConfigFileToPaths []DescribeContainerGroupsConfigFileVolumeConfigFileToPath2 `json:"ConfigFileVolumeConfigFileToPaths" xml:"ConfigFileVolumeConfigFileToPaths"`
 }
 

+ 6 - 6
services/eci/update_container_group.go

@@ -154,9 +154,9 @@ type UpdateContainerGroupImageRegistryCredential struct {
 }
 
 type UpdateContainerGroupDnsConfig struct {
-	NameServer []string                      `name:"NameServer"`
-	Search     []string                      `name:"Search"`
-	Option     *[]UpdateContainerGroupOption `name:"Option"`
+	NameServer []string                      `name:"NameServer" type:"Repeated"`
+	Search     []string                      `name:"Search" type:"Repeated"`
+	Option     *[]UpdateContainerGroupOption `name:"Option" type:"Repeated"`
 }
 
 type UpdateContainerGroupNFSVolume struct {
@@ -166,7 +166,7 @@ type UpdateContainerGroupNFSVolume struct {
 }
 
 type UpdateContainerGroupConfigFileVolume struct {
-	ConfigFileToPath *[]UpdateContainerGroupConfigFileToPath `name:"ConfigFileToPath"`
+	ConfigFileToPath *[]UpdateContainerGroupConfigFileToPath `name:"ConfigFileToPath" type:"Repeated"`
 }
 
 type UpdateContainerGroupConfigFileToPath struct {
@@ -194,7 +194,7 @@ type UpdateContainerGroupTcpSocket struct {
 }
 
 type UpdateContainerGroupExec struct {
-	Command []string `name:"Command"`
+	Command []string `name:"Command" type:"Repeated"`
 }
 
 type UpdateContainerGroupHttpGet struct {
@@ -221,7 +221,7 @@ type UpdateContainerGroupSecurityContext struct {
 }
 
 type UpdateContainerGroupCapability struct {
-	Add []string `name:"Add"`
+	Add []string `name:"Add" type:"Repeated"`
 }
 
 type UpdateContainerGroupEnvironmentVar struct {