Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
dfget&&supernode: cleanup code based on staticcheck warnings
Browse files Browse the repository at this point in the history
Signed-off-by: hwdef <[email protected]>
  • Loading branch information
hwdef committed Oct 9, 2019
1 parent 0b55c4e commit 6ca6927
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
12 changes: 6 additions & 6 deletions dfget/core/api/supernode_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion dfget/core/downloader/p2p_downloader/power_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion dfget/core/uploader/peer_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,6 @@ func (ps *peerServer) waitForShutdown() {
if ps.finished == nil {
return
}

for {
select {
case _, notClose := <-ps.finished:
Expand Down
2 changes: 1 addition & 1 deletion supernode/daemon/mgr/pieceerror/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 6ca6927

Please sign in to comment.