fix staticcheck errors (#191)

* run go mod tidy

* omit receiver name if unused

* remove unused type testkey in tests

* fix duplicate import of go-multiaddr

* fix use of deprecated peer.IDB58{Encode,Decode}

* use bytes.Equal instead of bytes.Compare

* fix unnecessary assigments to blank identifier

* use time.Until instead of t.Sub(time.Now())

* fix use of deprecated go-multihash.ID

* add missing error check in envelope test

* fix error check in tests
This commit is contained in:
Marten Seemann
2021-03-31 06:13:36 +07:00
committed by GitHub
parent cfab100b7b
commit ea8b36912f
12 changed files with 24 additions and 62 deletions

View File

@@ -3,7 +3,6 @@ package peer
import (
"fmt"
"github.com/multiformats/go-multiaddr"
ma "github.com/multiformats/go-multiaddr"
)
@@ -64,7 +63,7 @@ func SplitAddr(m ma.Multiaddr) (transport ma.Multiaddr, id ID) {
// AddrInfoFromString builds an AddrInfo from the string representation of a Multiaddr
func AddrInfoFromString(s string) (*AddrInfo, error) {
a, err := multiaddr.NewMultiaddr(s)
a, err := ma.NewMultiaddr(s)
if err != nil {
return nil, err
}

View File

@@ -87,8 +87,7 @@ func TestAddrInfosFromP2pAddrs(t *testing.T) {
if len(infos) != 0 {
t.Fatal("expected no addrs")
}
infos, err = AddrInfosFromP2pAddrs(nil)
if err == nil {
if _, err = AddrInfosFromP2pAddrs(nil); err == nil {
t.Fatal("expected nil multiaddr to fail")
}

View File

@@ -226,7 +226,7 @@ func IDFromPublicKey(pk ic.PubKey) (ID, error) {
}
var alg uint64 = mh.SHA2_256
if AdvancedEnableInlining && len(b) <= maxInlineKeyLength {
alg = mh.ID
alg = mh.IDENTITY
}
hash, _ := mh.Sum(b, alg, -1)
return ID(hash), nil

View File

@@ -190,7 +190,7 @@ func (r *PeerRecord) Equal(other *PeerRecord) bool {
if len(r.Addrs) != len(other.Addrs) {
return false
}
for i, _ := range r.Addrs {
for i := range r.Addrs {
if !r.Addrs[i].Equal(other.Addrs[i]) {
return false
}

View File

@@ -63,7 +63,7 @@ func (ps *Set) TryAdd(p ID) bool {
func (ps *Set) Peers() []ID {
ps.lk.Lock()
out := make([]ID, 0, len(ps.ps))
for p, _ := range ps.ps {
for p := range ps.ps {
out = append(out, p)
}
ps.lk.Unlock()