فهرست منبع

sdk support map

wenzuochao 6 سال پیش
والد
کامیت
ec9d51ac0d
3فایلهای تغییر یافته به همراه19 افزوده شده و 8 حذف شده
  1. 5 0
      sdk/requests/acs_request.go
  2. 11 5
      sdk/requests/acs_request_test.go
  3. 3 3
      sdk/requests/common_request.go

+ 5 - 0
sdk/requests/acs_request.go

@@ -15,6 +15,7 @@
 package requests
 
 import (
+	"encoding/json"
 	"fmt"
 	"io"
 	"reflect"
@@ -313,6 +314,10 @@ func flatRepeatedList(dataValue reflect.Value, request AcsRequest, position, pre
 				// simple param
 				key := prefix + name
 				value := dataValue.Field(i).String()
+				if dataValue.Field(i).Kind().String() == "map" {
+					byt, _ := json.Marshal(dataValue.Field(i).Interface())
+					value = string(byt)
+				}
 				err = addParam(request, fieldPosition, key, value)
 				if err != nil {
 					return

+ 11 - 5
sdk/requests/acs_request_test.go

@@ -120,11 +120,12 @@ func Test_AcsRequest(t *testing.T) {
 type AcsRequestTest struct {
 	*baseRequest
 	Ontology AcsRequest
-	Query    string    `position:"Query" name:"Query"`
-	Header   string    `position:"Header" name:"Header"`
-	Path     string    `position:"Path" name:"Path"`
-	Body     string    `position:"Body" name:"Body"`
-	TypeAcs  *[]string `position:"type" name:"type" type:"Repeated"`
+	Query    string                 `position:"Query" name:"Query"`
+	Header   string                 `position:"Header" name:"Header"`
+	Path     string                 `position:"Path" name:"Path"`
+	Body     string                 `position:"Body" name:"Body"`
+	Target   map[string]interface{} `position:"Query" name:"Target"`
+	TypeAcs  *[]string              `position:"type" name:"type" type:"Repeated"`
 }
 
 func (r AcsRequestTest) BuildQueries() string {
@@ -154,6 +155,10 @@ func Test_AcsRequest_InitParams(t *testing.T) {
 		Header:      "header value",
 		Path:        "path value",
 		Body:        "body value",
+		Target: map[string]interface{}{
+			"key":   "test",
+			"value": 1234,
+		},
 	}
 	tmp := []string{r.Query, r.Header}
 	r.TypeAcs = &tmp
@@ -162,6 +167,7 @@ func Test_AcsRequest_InitParams(t *testing.T) {
 
 	queries := r.GetQueryParams()
 	assert.Equal(t, "query value", queries["Query"])
+	assert.Equal(t, "{\"key\":\"test\",\"value\":1234}", queries["Target"])
 	headers := r.GetHeaders()
 	assert.Equal(t, "header value", headers["Header"])
 	// TODO: check the body & path

+ 3 - 3
sdk/requests/common_request.go

@@ -11,9 +11,9 @@ import (
 type CommonRequest struct {
 	*baseRequest
 
-	Version string
-	ApiName string
-	Product string
+	Version     string
+	ApiName     string
+	Product     string
 	ServiceCode string
 
 	// roa params