Skip to content

Commit

Permalink
chore: make gocritic happier
Browse files Browse the repository at this point in the history
Solve most results of:
```console
$ gocritic check ./... 2>&1 | grep -v "_test\.go:"
```
  • Loading branch information
Jorropo committed Feb 27, 2023
1 parent 00e0249 commit 0d5d1ca
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion bitswap/client/internal/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ func (s *Session) resetIdleTick() {
avLat := s.latencyTrkr.averageLatency()
tickDelay = s.baseTickDelay + (3 * avLat)
}
tickDelay = tickDelay * time.Duration(1+s.consecutiveTicks)
tickDelay *= time.Duration(1 + s.consecutiveTicks)
s.idleTick.Reset(tickDelay)
}

Expand Down
7 changes: 4 additions & 3 deletions bitswap/client/internal/session/sessionwantsender.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,11 +653,12 @@ func (sws *sessionWantSender) updateWantBlockPresence(c cid.Cid, p peer.ID) {

// If the peer sent us a HAVE or DONT_HAVE for the cid, adjust the
// block presence for the peer / cid combination
if sws.bpm.PeerHasBlock(p, c) {
switch {
case sws.bpm.PeerHasBlock(p, c):
wi.setPeerBlockPresence(p, BPHave)
} else if sws.bpm.PeerDoesNotHaveBlock(p, c) {
case sws.bpm.PeerDoesNotHaveBlock(p, c):
wi.setPeerBlockPresence(p, BPDontHave)
} else {
default:
wi.setPeerBlockPresence(p, BPUnknown)
}
}
Expand Down
6 changes: 3 additions & 3 deletions bitswap/decision/forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package decision
import "github.com/ipfs/go-libipfs/bitswap/server"

type (
// DEPRECATED use server.Receipt instead
// Deprecated: use server.Receipt instead
Receipt = server.Receipt
// DEPRECATED use server.ScoreLedger instead
// Deprecated: use server.ScoreLedger instead
ScoreLedger = server.ScoreLedger
// DEPRECATED use server.ScorePeerFunc instead
// Deprecated: use server.ScorePeerFunc instead
ScorePeerFunc = server.ScorePeerFunc
)
2 changes: 1 addition & 1 deletion bitswap/message/pb/cid.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ func (c *Cid) UnmarshalJSON(data []byte) error {
}

func (c Cid) Equal(other Cid) bool {
return c.Cid.Equals(c.Cid)
return c.Cid.Equals(other.Cid)
}
8 changes: 4 additions & 4 deletions bitswap/wantlist/forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import (
)

type (
// DEPRECATED use wantlist.Entry instead
// Deprecated: use wantlist.Entry instead
Entry = wantlist.Entry
// DEPRECATED use wantlist.Wantlist instead
// Deprecated: use wantlist.Wantlist instead
Wantlist = wantlist.Wantlist
)

// DEPRECATED use wantlist.New instead
// Deprecated: use wantlist.New instead
func New() *Wantlist {
return wantlist.New()
}

// DEPRECATED use wantlist.NewRefEntry instead
// Deprecated: use wantlist.NewRefEntry instead
func NewRefEntry(c cid.Cid, p int32) Entry {
return wantlist.NewRefEntry(c, p)
}
3 changes: 1 addition & 2 deletions files/multifilereader.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ func (mfr *MultiFileReader) Read(buf []byte) (written int, err error) {
}

// otherwise, read from file data
switch f := mfr.currentFile.(type) {
case File:
if f, ok := mfr.currentFile.(File); ok {
written, err = f.Read(buf)
if err != io.EOF {
return written, err
Expand Down
2 changes: 1 addition & 1 deletion files/serialfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (f *serialFile) Stat() os.FileInfo {

func (f *serialFile) Size() (int64, error) {
if !f.stat.IsDir() {
//something went terribly, terribly wrong
// something went terribly, terribly wrong
return 0, errors.New("serialFile is not a directory")
}

Expand Down
13 changes: 7 additions & 6 deletions gateway/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,17 +563,18 @@ func webRequestError(w http.ResponseWriter, err *requestError) {
}

func webError(w http.ResponseWriter, err error, defaultCode int) {
if errors.Is(err, path.ErrInvalidPath{}) {
switch {
case errors.Is(err, path.ErrInvalidPath{}):
webErrorWithCode(w, err, http.StatusBadRequest)
} else if isErrNotFound(err) {
case isErrNotFound(err):
webErrorWithCode(w, err, http.StatusNotFound)
} else if errors.Is(err, ErrGatewayTimeout) {
case errors.Is(err, ErrGatewayTimeout):
webErrorWithCode(w, err, http.StatusGatewayTimeout)
} else if errors.Is(err, ErrBadGateway) {
case errors.Is(err, ErrBadGateway):
webErrorWithCode(w, err, http.StatusBadGateway)
} else if errors.Is(err, context.DeadlineExceeded) || err == context.DeadlineExceeded {
case errors.Is(err, context.DeadlineExceeded):
webErrorWithCode(w, err, http.StatusGatewayTimeout)
} else {
default:
webErrorWithCode(w, err, defaultCode)
}
}
Expand Down

0 comments on commit 0d5d1ca

Please sign in to comment.