mirror of
https://github.com/libp2p/go-libp2p-core.git
synced 2026-08-18 15:03:28 +08:00
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:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user