From 6d12fab450b0d313b66264a222e449ce38ffac73 Mon Sep 17 00:00:00 2001 From: 0xTylerHolmes Date: Mon, 23 Oct 2023 17:08:55 -0500 Subject: [PATCH] ci lints --- api/v1/peers.go | 26 ++++++++++++++------------ multi/nodepeers.go | 2 +- testclients/erroring.go | 4 ++-- testclients/sleepy.go | 4 ++-- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/api/v1/peers.go b/api/v1/peers.go index fd3a99cf..f5a22121 100644 --- a/api/v1/peers.go +++ b/api/v1/peers.go @@ -7,7 +7,7 @@ import ( "github.com/pkg/errors" ) -// Peer contains all the available information about a nodes peer +// Peer contains all the available information about a nodes peer. type Peer struct { PeerID string `json:"peer_id"` Enr string `json:"enr,omitempty"` @@ -24,20 +24,20 @@ type peerJSON struct { Direction string `json:"direction"` } -// validPeerDirections are all the accepted options for peer direction +// validPeerDirections are all the accepted options for peer direction. var validPeerDirections = map[string]int{"inbound": 1, "outbound": 1} -// validPeerStates are all the accepted options for peer states +// validPeerStates are all the accepted options for peer states. var validPeerStates = map[string]int{"connected": 1, "connecting": 1, "disconnected": 1, "disconnecting": 1} func (p *Peer) MarshalJSON() ([]byte, error) { // make sure we have valid peer states and directions - _, exists := validPeerDirections[fmt.Sprintf("%s", p.Direction)] - if exists == false { + _, exists := validPeerDirections[p.Direction] + if !exists { return nil, errors.New(fmt.Sprintf("invalid value for peer direction: %s", p.Direction)) } _, exists = validPeerStates[p.State] - if exists == false { + if !exists { return nil, errors.New(fmt.Sprintf("invalid value for peer state: %s", p.State)) } @@ -52,30 +52,32 @@ func (p *Peer) MarshalJSON() ([]byte, error) { func (p *Peer) UnmarshalJSON(input []byte) error { var peerJSON peerJSON - err := json.Unmarshal(input, &peerJSON) - if err = json.Unmarshal(input, &peerJSON); err != nil { + + if err := json.Unmarshal(input, &peerJSON); err != nil { return errors.Wrap(err, "invalid JSON") } _, ok := validPeerStates[peerJSON.State] - if ok == false { + if !ok { return errors.New(fmt.Sprintf("invalid value for peer state: %s", peerJSON.State)) } p.State = peerJSON.State _, ok = validPeerDirections[peerJSON.Direction] - if ok == false { + if !ok { return errors.New(fmt.Sprintf("invalid value for peer direction: %s", peerJSON.Direction)) } p.Direction = peerJSON.Direction p.Enr = peerJSON.Enr p.PeerID = peerJSON.PeerID p.LastSeenP2PAddress = peerJSON.LastSeenP2PAddress + return nil } -func (e *Peer) String() string { - data, err := json.Marshal(e) +func (p *Peer) String() string { + data, err := json.Marshal(p) if err != nil { return fmt.Sprintf("ERR: %v", err) } + return string(data) } diff --git a/multi/nodepeers.go b/multi/nodepeers.go index 3155ac80..182fd9d7 100644 --- a/multi/nodepeers.go +++ b/multi/nodepeers.go @@ -21,7 +21,7 @@ import ( apiv1 "github.com/attestantio/go-eth2-client/api/v1" ) -// NodePeers provides the peers of the node +// NodePeers provides the peers of the node. func (s *Service) NodePeers(ctx context.Context, opts *api.PeerOpts) (*api.Response[[]*apiv1.Peer], error) { res, err := s.doCall(ctx, func(ctx context.Context, client consensusclient.Service) (interface{}, error) { nodePeers, err := client.(consensusclient.NodePeersProvider).NodePeers(ctx, opts) diff --git a/testclients/erroring.go b/testclients/erroring.go index cdecbdb5..b038d774 100644 --- a/testclients/erroring.go +++ b/testclients/erroring.go @@ -560,8 +560,8 @@ func (s *Erroring) NodeSyncing(ctx context.Context) (*api.Response[*apiv1.SyncSt return next.NodeSyncing(ctx) } -// NodePeers provides the peers of the node -func (s *Erroring) NodePeers(ctx context.Context, opts *api.PeerOpts) (*api.Response[*apiv1.Peers], error) { +// NodePeers provides the peers of the node. +func (s *Erroring) NodePeers(ctx context.Context, opts *api.PeerOpts) (*api.Response[[]*apiv1.Peer], error) { if err := s.maybeError(ctx); err != nil { return nil, err } diff --git a/testclients/sleepy.go b/testclients/sleepy.go index 489a7f46..0b8dd973 100644 --- a/testclients/sleepy.go +++ b/testclients/sleepy.go @@ -426,8 +426,8 @@ func (s *Sleepy) NodeSyncing(ctx context.Context) (*api.Response[*apiv1.SyncStat return next.NodeSyncing(ctx) } -// NodePeers provides the peers of the node -func (s *Sleepy) NodePeers(ctx context.Context, opts *api.PeerOpts) (*api.Response[*apiv1.Peers], error) { +// NodePeers provides the peers of the node. +func (s *Sleepy) NodePeers(ctx context.Context, opts *api.PeerOpts) (*api.Response[[]*apiv1.Peer], error) { s.sleep(ctx) next, isNext := s.next.(consensusclient.NodePeersProvider) if !isNext {