Merge pull request #4652 from Loyalsoldier/httplib-fix-lint

Fix lint and format code in client/httplib dir
This commit is contained in:
Ming Deng 2021-06-07 13:01:48 +08:00 committed by GitHub
commit b420b064d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 13 additions and 19 deletions

View File

@ -5,6 +5,7 @@
- Infra: use dependabot to update dependencies. [4623](https://github.com/beego/beego/pull/4623)
- Lint: use golangci-lint. [4619](https://github.com/beego/beego/pull/4619)
- 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)
- Fix lint and format code in client/orm dir [4653](https://github.com/beego/beego/pull/4653)

View File

@ -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()

View File

@ -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",

View File

@ -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))
}

View File

@ -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) {

View File

@ -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")

View File

@ -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

View File

@ -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

View File

@ -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 {