From 6ca69277b793818a1f3120f7cc79653697dde53d Mon Sep 17 00:00:00 2001 From: hwdef Date: Sun, 29 Sep 2019 16:35:47 +0800 Subject: [PATCH] dfget&&supernode: cleanup code based on staticcheck warnings Signed-off-by: hwdef --- dfget/core/api/supernode_api_test.go | 12 ++++++------ dfget/core/downloader/p2p_downloader/power_client.go | 2 +- dfget/core/uploader/peer_server.go | 1 - supernode/daemon/mgr/pieceerror/manager.go | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/dfget/core/api/supernode_api_test.go b/dfget/core/api/supernode_api_test.go index 55824d5e7..126df9b6b 100644 --- a/dfget/core/api/supernode_api_test.go +++ b/dfget/core/api/supernode_api_test.go @@ -129,28 +129,28 @@ func (s *SupernodeAPITestSuite) TestSupernodeAPI_get(c *check.C) { } api := s.api.(*supernodeAPI) - f := func(code int, res string, e error) (*testRes, error, string) { + f := func(code int, res string, e error) (*testRes, string, error) { s.mock.GetFunc = s.mock.CreateGetFunc(code, []byte(res), e) msg := fmt.Sprintf("code:%d res:%s e:%v", code, res, e) resp := new(testRes) err := api.get("http://localhost", resp) - return resp, err, msg + return resp, msg, err } - r, e, m := f(0, "test", nil) + r, m, e := f(0, "test", nil) c.Assert(r.A, check.Equals, 0, check.Commentf(m)) c.Assert(e.Error(), check.Equals, "0:test", check.Commentf(m)) - r, e, m = f(0, "x", fmt.Errorf("test error")) + r, m, e = f(0, "x", fmt.Errorf("test error")) c.Assert(r.A, check.Equals, 0, check.Commentf(m)) c.Assert(e.Error(), check.Equals, "test error", check.Commentf(m)) - r, e, m = f(200, "x", nil) + r, m, e = f(200, "x", nil) c.Assert(r.A, check.Equals, 0, check.Commentf(m)) c.Assert(strings.Contains(e.Error(), "invalid character"), check.Equals, true, check.Commentf(m)) - r, e, m = f(200, `{"A":1}`, nil) + r, m, e = f(200, `{"A":1}`, nil) c.Assert(r.A, check.Equals, 1, check.Commentf(m)) c.Assert(e, check.IsNil, check.Commentf(m)) diff --git a/dfget/core/downloader/p2p_downloader/power_client.go b/dfget/core/downloader/p2p_downloader/power_client.go index 0d4349d7a..70ceb14c6 100644 --- a/dfget/core/downloader/p2p_downloader/power_client.go +++ b/dfget/core/downloader/p2p_downloader/power_client.go @@ -140,7 +140,7 @@ func (pc *PowerClient) downloadPiece() (content *bytes.Buffer, e error) { if pc.total, e = content.ReadFrom(limitReader); e != nil { return nil, e } - pc.readCost = time.Now().Sub(startTime) + pc.readCost = time.Since(startTime) // Verify md5 code if realMd5 := limitReader.Md5(); realMd5 != pieceMD5 { diff --git a/dfget/core/uploader/peer_server.go b/dfget/core/uploader/peer_server.go index 4cd6d95cf..bdc451637 100644 --- a/dfget/core/uploader/peer_server.go +++ b/dfget/core/uploader/peer_server.go @@ -448,7 +448,6 @@ func (ps *peerServer) waitForShutdown() { if ps.finished == nil { return } - for { select { case _, notClose := <-ps.finished: diff --git a/supernode/daemon/mgr/pieceerror/manager.go b/supernode/daemon/mgr/pieceerror/manager.go index 3405df963..111a0df05 100644 --- a/supernode/daemon/mgr/pieceerror/manager.go +++ b/supernode/daemon/mgr/pieceerror/manager.go @@ -70,7 +70,7 @@ type Manager struct { func NewManager(cfg *config.Config, gcManager mgr.GCMgr, cdnManager mgr.CDNMgr) (*Manager, error) { return &Manager{ cfg: cfg, - handlers: make(map[string]Handler, 0), + handlers: make(map[string]Handler), gcManager: gcManager, cdnManager: cdnManager, pieceErrChan: make(chan *types.PieceErrorRequest, ErrHandlerChanSize),