Skip to content

Commit

Permalink
support extends parameters in runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
yndu13 committed Mar 6, 2024
1 parent 16aef0a commit 296a645
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
10 changes: 10 additions & 0 deletions golang/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,15 @@ func (client *Client) DoRequest(params *Params, request *OpenApiRequest, runtime

}

extendsHeaders := make(map[string]*string)
if !tea.BoolValue(util.IsUnset(runtime.ExtendsParameters)) {
extendsParameters := runtime.ExtendsParameters
if !tea.BoolValue(util.IsUnset(extendsParameters.Headers)) {
extendsHeaders = extendsParameters.Headers
}

}

request_.Query = tea.Merge(globalQueries,
request.Query)
// endpoint is setted in product client
Expand All @@ -1294,6 +1303,7 @@ func (client *Client) DoRequest(params *Params, request *OpenApiRequest, runtime
"x-acs-signature-nonce": util.GetNonce(),
"accept": tea.String("application/json"),
}, globalHeaders,
extendsHeaders,
request.Headers)
if tea.BoolValue(util.EqualString(params.Style, tea.String("RPC"))) {
headers, _err := client.GetRpcHeaders()
Expand Down
26 changes: 18 additions & 8 deletions golang/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,21 @@ func CreateConfig() (_result *Config) {
}

func CreateRuntimeOptions() (_result *util.RuntimeOptions) {
extendsParameters := &util.ExtendsParameters{
Headers: map[string]*string{
"extends-key": tea.String("extends-value"),
},
}
runtime := &util.RuntimeOptions{
ReadTimeout: tea.Int(4000),
ConnectTimeout: tea.Int(4000),
MaxIdleConns: tea.Int(100),
Autoretry: tea.Bool(true),
MaxAttempts: tea.Int(1),
BackoffPolicy: tea.String("no"),
BackoffPeriod: tea.Int(1),
IgnoreSSL: tea.Bool(true),
ReadTimeout: tea.Int(4000),
ConnectTimeout: tea.Int(4000),
MaxIdleConns: tea.Int(100),
Autoretry: tea.Bool(true),
MaxAttempts: tea.Int(1),
BackoffPolicy: tea.String("no"),
BackoffPeriod: tea.Int(1),
IgnoreSSL: tea.Bool(true),
ExtendsParameters: extendsParameters,
}
_result = runtime
return _result
Expand Down Expand Up @@ -509,6 +515,7 @@ func TestCallApiForRPCWithV3Sign_AK_Form(t *testing.T) {
tea_util.AssertEqual(t, true, has)
tea_util.AssertEqual(t, "sdk", headers["for-test"])
tea_util.AssertEqual(t, "global-value", headers["global-key"])
tea_util.AssertEqual(t, "extends-value", headers["extends-key"])
tea_util.AssertNotNil(t, headers["x-acs-date"])
tea_util.AssertEqual(t, "application/json", headers["accept"])
tea_util.AssertNotNil(t, headers["x-acs-signature-nonce"])
Expand Down Expand Up @@ -568,6 +575,7 @@ func TestCallApiForRPCWithV3Sign_Anonymous_JSON(t *testing.T) {
tea_util.AssertEqual(t, true, has)
tea_util.AssertEqual(t, "sdk", headers["for-test"])
tea_util.AssertEqual(t, "global-value", headers["global-key"])
tea_util.AssertEqual(t, "extends-value", headers["extends-key"])
tea_util.AssertNotNil(t, headers["x-acs-date"])
tea_util.AssertEqual(t, "application/json", headers["accept"])
tea_util.AssertNotNil(t, headers["x-acs-signature-nonce"])
Expand Down Expand Up @@ -630,6 +638,7 @@ func TestCallApiForROAWithV3Sign_AK_Form(t *testing.T) {
tea_util.AssertEqual(t, true, has)
tea_util.AssertEqual(t, "sdk", headers["for-test"])
tea_util.AssertEqual(t, "global-value", headers["global-key"])
tea_util.AssertEqual(t, "extends-value", headers["extends-key"])
tea_util.AssertNotNil(t, headers["x-acs-date"])
tea_util.AssertEqual(t, "application/json", headers["accept"])
tea_util.AssertNotNil(t, headers["x-acs-signature-nonce"])
Expand Down Expand Up @@ -689,6 +698,7 @@ func TestCallApiForROAWithV3Sign_Anonymous_JSON(t *testing.T) {
tea_util.AssertEqual(t, true, has)
tea_util.AssertEqual(t, "sdk", headers["for-test"])
tea_util.AssertEqual(t, "global-value", headers["global-key"])
tea_util.AssertEqual(t, "extends-value", headers["extends-key"])
tea_util.AssertNotNil(t, headers["x-acs-date"])
tea_util.AssertEqual(t, "application/json", headers["accept"])
tea_util.AssertNotNil(t, headers["x-acs-signature-nonce"])
Expand Down
2 changes: 1 addition & 1 deletion golang/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.4
github.com/alibabacloud-go/openapi-util v0.1.0
github.com/alibabacloud-go/tea v1.2.1
github.com/alibabacloud-go/tea-utils/v2 v2.0.4
github.com/alibabacloud-go/tea-utils/v2 v2.0.5
github.com/alibabacloud-go/tea-xml v1.1.3
github.com/aliyun/credentials-go v1.3.1
github.com/clbanning/mxj/v2 v2.5.5 // indirect
Expand Down
8 changes: 8 additions & 0 deletions main.tea
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,13 @@ api doRequest(params: Params, request: OpenApiRequest, runtime: Util.RuntimeOpti
globalHeaders = globalParams.headers;
}
}
var extendsHeaders : map[string]string = {};
if (!Util.isUnset(runtime.extendsParameters)) {
var extendsParameters = runtime.extendsParameters;
if (!Util.isUnset(extendsParameters.headers)) {
extendsHeaders = extendsParameters.headers;
}
}
__request.query = {
...globalQueries,
...request.query,
Expand All @@ -688,6 +695,7 @@ api doRequest(params: Params, request: OpenApiRequest, runtime: Util.RuntimeOpti
x-acs-signature-nonce = Util.getNonce(),
accept = 'application/json',
...globalHeaders,
...extendsHeaders,
...request.headers,
};
if (Util.equalString(params.style, 'RPC')) {
Expand Down

0 comments on commit 296a645

Please sign in to comment.