From c28ae80b11d75c38f88b13d2e7694641ee030c74 Mon Sep 17 00:00:00 2001 From: loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com> Date: Sun, 6 Jun 2021 20:41:10 +0800 Subject: [PATCH] Fix lint and format code in client/httplib dir --- CHANGELOG.md | 1 + client/httplib/filter/opentracing/filter.go | 2 -- client/httplib/filter/prometheus/filter.go | 7 ++++--- client/httplib/httplib.go | 1 - client/httplib/httplib_test.go | 2 -- client/httplib/mock/mock_condition_test.go | 5 ----- client/httplib/mock/mock_test.go | 2 -- client/httplib/setting.go | 6 ++++-- client/httplib/testing/client.go | 6 ++++-- 9 files changed, 13 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 057e5a39..c3a27bad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Lint: use golangci-lint. [4619](https://github.com/beego/beego/pull/4619) - Fix lint and format code in adapter/httplib dir [4648](https://github.com/beego/beego/pull/4648) - Chore: format code. [4615](https://github.com/beego/beego/pull/4615) +- Fix lint and format code in client/httplib dir [4652](https://github.com/beego/beego/pull/4652) - Test on Go v1.15.x & v1.16.x. [4614](https://github.com/beego/beego/pull/4614) - Env: non-empty GOBIN & GOPATH. [4613](https://github.com/beego/beego/pull/4613) - Chore: update dependencies. [4611](https://github.com/beego/beego/pull/4611) diff --git a/client/httplib/filter/opentracing/filter.go b/client/httplib/filter/opentracing/filter.go index a46effc8..aef20e66 100644 --- a/client/httplib/filter/opentracing/filter.go +++ b/client/httplib/filter/opentracing/filter.go @@ -35,9 +35,7 @@ type FilterChainBuilder struct { } func (builder *FilterChainBuilder) FilterChain(next httplib.Filter) httplib.Filter { - return func(ctx context.Context, req *httplib.BeegoHTTPRequest) (*http.Response, error) { - method := req.GetRequest().Method operationName := method + "#" + req.GetRequest().URL.String() diff --git a/client/httplib/filter/prometheus/filter.go b/client/httplib/filter/prometheus/filter.go index 5761eb7e..e93b2298 100644 --- a/client/httplib/filter/prometheus/filter.go +++ b/client/httplib/filter/prometheus/filter.go @@ -32,11 +32,12 @@ type FilterChainBuilder struct { RunMode string } -var summaryVec prometheus.ObserverVec -var initSummaryVec sync.Once +var ( + summaryVec prometheus.ObserverVec + initSummaryVec sync.Once +) func (builder *FilterChainBuilder) FilterChain(next httplib.Filter) httplib.Filter { - initSummaryVec.Do(func() { summaryVec = prometheus.NewSummaryVec(prometheus.SummaryOpts{ Name: "beego", diff --git a/client/httplib/httplib.go b/client/httplib/httplib.go index b102f687..ca643b33 100644 --- a/client/httplib/httplib.go +++ b/client/httplib/httplib.go @@ -400,7 +400,6 @@ func (b *BeegoHTTPRequest) handleFileToBody(bodyWriter *multipart.Writer, formna "could not create form file, formname: %s, filename: %s", formname, filename)) } fh, err := os.Open(filename) - if err != nil { logs.Error(errFmt, berror.Wrapf(err, ReadFileFailed, "could not open this file %s", filename)) } diff --git a/client/httplib/httplib_test.go b/client/httplib/httplib_test.go index 491b1b9f..4be9fd43 100644 --- a/client/httplib/httplib_test.go +++ b/client/httplib/httplib_test.go @@ -63,7 +63,6 @@ func TestDoRequest(t *testing.T) { if elapsedTime < delayedTime { t.Errorf("Not enough retries. Took %dms. Delay was meant to take %dms", elapsedTime, delayedTime) } - } func TestGet(t *testing.T) { @@ -248,7 +247,6 @@ func TestToJson(t *testing.T) { t.Fatal("response is not valid ip") } } - } func TestToFile(t *testing.T) { diff --git a/client/httplib/mock/mock_condition_test.go b/client/httplib/mock/mock_condition_test.go index 4fc6d377..9ebdab70 100644 --- a/client/httplib/mock/mock_condition_test.go +++ b/client/httplib/mock/mock_condition_test.go @@ -23,10 +23,6 @@ import ( "github.com/beego/beego/v2/client/httplib" ) -func init() { - -} - func TestSimpleCondition_MatchPath(t *testing.T) { sc := NewSimpleCondition("/abc/s") res := sc.Match(context.Background(), httplib.Get("http://localhost:8080/abc/s")) @@ -72,7 +68,6 @@ func TestSimpleCondition_MatchHeader(t *testing.T) { } func TestSimpleCondition_MatchBodyField(t *testing.T) { - sc := NewSimpleCondition("/abc/s") req := httplib.Post("http://localhost:8080/abc/s") diff --git a/client/httplib/mock/mock_test.go b/client/httplib/mock/mock_test.go index 2972cf8f..754841c3 100644 --- a/client/httplib/mock/mock_test.go +++ b/client/httplib/mock/mock_test.go @@ -26,7 +26,6 @@ import ( ) func TestStartMock(t *testing.T) { - // httplib.defaultSetting.FilterChains = []httplib.FilterChain{mockFilter.FilterChain} stub := StartMock() @@ -41,7 +40,6 @@ func TestStartMock(t *testing.T) { assert.Equal(t, expectedErr, err) assert.Equal(t, expectedResp, resp) - } // TestStartMock_Isolation Test StartMock that diff --git a/client/httplib/setting.go b/client/httplib/setting.go index 2d7a0eed..fa034413 100644 --- a/client/httplib/setting.go +++ b/client/httplib/setting.go @@ -68,8 +68,10 @@ var defaultSetting = BeegoHTTPSettings{ FilterChains: make([]FilterChain, 0, 4), } -var defaultCookieJar http.CookieJar -var settingMutex sync.Mutex +var ( + defaultCookieJar http.CookieJar + settingMutex sync.Mutex +) // AddDefaultFilter add a new filter into defaultSetting // Be careful about using this method if you invoke SetDefaultSetting somewhere diff --git a/client/httplib/testing/client.go b/client/httplib/testing/client.go index 517e0722..43e2e968 100644 --- a/client/httplib/testing/client.go +++ b/client/httplib/testing/client.go @@ -18,8 +18,10 @@ import ( "github.com/beego/beego/v2/client/httplib" ) -var port = "" -var baseURL = "http://localhost:" +var ( + port = "" + baseURL = "http://localhost:" +) // TestHTTPRequest beego test request client type TestHTTPRequest struct {