Skip to content

Commit

Permalink
cleanup unused parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonTian authored and yndu13 committed Jul 29, 2024
1 parent a0194b9 commit ee9cb9f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
6 changes: 3 additions & 3 deletions sdk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (client *Client) getHttpProxy(scheme string) (proxy *url.URL, err error) {
return proxy, err
}

func (client *Client) getNoProxy(scheme string) []string {
func (client *Client) getNoProxy() []string {
var urls []string
if client.GetNoProxy() != "" {
urls = strings.Split(client.noProxy, ",")
Expand Down Expand Up @@ -369,7 +369,7 @@ func (client *Client) DoAction(request requests.AcsRequest, response responses.A
func (client *Client) GetEndpointRules(regionId string, product string) (endpointRaw string, err error) {
if client.EndpointType == "regional" {
if regionId == "" {
err = fmt.Errorf("RegionId is empty, please set a valid RegionId.")
err = fmt.Errorf("RegionId is empty, please set a valid RegionId")
return "", err
}
endpointRaw = strings.Replace("<product><network>.<region_id>.aliyuncs.com", "<region_id>", regionId, 1)
Expand Down Expand Up @@ -584,7 +584,7 @@ func (client *Client) DoActionWithSigner(request requests.AcsRequest, response r
return err
}

noProxy := client.getNoProxy(httpRequest.URL.Scheme)
noProxy := client.getNoProxy()

var flag bool
for _, value := range noProxy {
Expand Down
8 changes: 7 additions & 1 deletion sdk/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ func TestClient_BuildRequestWithSigner2(t *testing.T) {
request.Domain = ""
httprequest, err = client.buildRequestWithSigner(request, signer)
assert.Nil(t, httprequest)
assert.Equal(t, "RegionId is empty, please set a valid RegionId.", err.Error())
assert.Equal(t, "RegionId is empty, please set a valid RegionId", err.Error())

//Test: exceptional rule
client.regionId = "regionid"
Expand Down Expand Up @@ -811,30 +811,36 @@ func TestClient_AppendUserAgent(t *testing.T) {
// Test set client useragent.
client.AppendUserAgent("test", "1.01")
httpRequest, err = client.buildRequestWithSigner(request, signer)
assert.Nil(t, err)
assert.Equal(t, DefaultUserAgent+" test/1.01", httpRequest.Header.Get("User-Agent"))

// Test set request useragent. And request useragent has a higner priority than client's.
request.AppendUserAgent("test", "2.01")
httpRequest, err = client.buildRequestWithSigner(request, signer)
assert.Nil(t, err)
assert.Equal(t, DefaultUserAgent+" test/2.01", httpRequest.Header.Get("User-Agent"))

client.AppendUserAgent("test", "2.02")
httpRequest, err = client.buildRequestWithSigner(request, signer)
assert.Nil(t, err)
assert.Equal(t, DefaultUserAgent+" test/2.01", httpRequest.Header.Get("User-Agent"))

// Test update request useragent.
request.AppendUserAgent("test", "2.02")
httpRequest, err = client.buildRequestWithSigner(request, signer)
assert.Nil(t, err)
assert.Equal(t, DefaultUserAgent+" test/2.02", httpRequest.Header.Get("User-Agent"))

// Test client can't modify DefaultUserAgent.
client.AppendUserAgent("core", "1.01")
httpRequest, err = client.buildRequestWithSigner(request, signer)
assert.Nil(t, err)
assert.Equal(t, DefaultUserAgent+" test/2.02", httpRequest.Header.Get("User-Agent"))

// Test request can't modify DefaultUserAgent.
request.AppendUserAgent("core", "1.01")
httpRequest, err = client.buildRequestWithSigner(request, signer)
assert.Nil(t, err)
assert.Equal(t, DefaultUserAgent+" test/2.02", httpRequest.Header.Get("User-Agent"))

request1 := requests.NewCommonRequest()
Expand Down
3 changes: 1 addition & 2 deletions sdk/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
)

var logChannel string
var defaultChannel = "AlibabaCloud"

type Logger struct {
*log.Logger
Expand Down Expand Up @@ -110,7 +109,7 @@ func (client *Client) printLog(fieldMap map[string]string, err error) {
logMsg = strings.Replace(logMsg, key, value, -1)
}
client.logger.lastLogMsg = logMsg
if client.logger.isOpen == true {
if client.logger.isOpen {
client.logger.Output(2, logMsg)
}
}
Expand Down

0 comments on commit ee9cb9f

Please sign in to comment.