Skip to content

Commit

Permalink
*: enable golangci-lint asciicheck and bodyclose (#28756)
Browse files Browse the repository at this point in the history
  • Loading branch information
tangenta authored Oct 15, 2021
1 parent ac9dcbb commit a11bb67
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ linters:
- staticcheck
- stylecheck
- gosec
- asciicheck
- bodyclose
linters-settings:
staticcheck:
checks: ["S1002","S1004","S1007","S1009","S1010","S1012","S1019","S1020","S1021","S1024","S1030","SA2*","SA3*","SA4009","SA5*","SA6000","SA6001","SA6005", "-SA2002"]
Expand Down
24 changes: 17 additions & 7 deletions domain/infosync/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,7 @@ func doRequest(ctx context.Context, addrs []string, route, method string, body i
req.Header.Set("Content-Type", "application/json")
}

res, err = util2.InternalHTTPClient().Do(req)
failpoint.Inject("FailPlacement", func(val failpoint.Value) {
if val.(bool) {
res = &http.Response{StatusCode: http.StatusNotFound, Body: http.NoBody}
err = nil
}
})
res, err = doRequestWithFailpoint(req)
if err == nil {
bodyBytes, err := io.ReadAll(res.Body)
if err != nil {
Expand All @@ -359,6 +353,21 @@ func doRequest(ctx context.Context, addrs []string, route, method string, body i
return nil, err
}

func doRequestWithFailpoint(req *http.Request) (resp *http.Response, err error) {
fpEnabled := false
failpoint.Inject("FailPlacement", func(val failpoint.Value) {
if val.(bool) {
fpEnabled = true
resp = &http.Response{StatusCode: http.StatusNotFound, Body: http.NoBody}
err = nil
}
})
if fpEnabled {
return
}
return util2.InternalHTTPClient().Do(req)
}

// GetAllRuleBundles is used to get all rule bundles from PD. It is used to load full rules from PD while fullload infoschema.
func GetAllRuleBundles(ctx context.Context) ([]*placement.Bundle, error) {
is, err := getGlobalInfoSyncer()
Expand Down Expand Up @@ -696,6 +705,7 @@ func (is *InfoSyncer) getPrometheusAddr() (string, error) {
if err != nil {
return "", err
}
defer resp.Body.Close()
var metricStorage metricStorage
dec := json.NewDecoder(resp.Body)
err = dec.Decode(&metricStorage)
Expand Down
3 changes: 2 additions & 1 deletion executor/infoschema_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2659,11 +2659,12 @@ func (e *TiFlashSystemTableRetriever) initialize(sctx sessionctx.Context, tiflas
if err != nil {
return errors.Trace(err)
}
_, err = util.InternalHTTPClient().Do(req)
resp, err := util.InternalHTTPClient().Do(req)
if err != nil {
sctx.GetSessionVars().StmtCtx.AppendWarning(err)
continue
}
resp.Body.Close()
e.instanceInfos = append(e.instanceInfos, tiflashInstanceInfo{
id: id,
url: url,
Expand Down
Loading

0 comments on commit a11bb67

Please sign in to comment.