Skip to content

Commit

Permalink
ci lints
Browse files Browse the repository at this point in the history
  • Loading branch information
0xTylerHolmes committed Oct 23, 2023
1 parent 0ab09d3 commit 6d12fab
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
26 changes: 14 additions & 12 deletions api/v1/peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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))

Check warning on line 37 in api/v1/peers.go

View workflow job for this annotation

GitHub Actions / lint

errorf: should replace errors.New(fmt.Sprintf(...)) with fmt.Errorf(...) (revive)
}
_, exists = validPeerStates[p.State]
if exists == false {
if !exists {
return nil, errors.New(fmt.Sprintf("invalid value for peer state: %s", p.State))

Check warning on line 41 in api/v1/peers.go

View workflow job for this annotation

GitHub Actions / lint

errorf: should replace errors.New(fmt.Sprintf(...)) with fmt.Errorf(...) (revive)
}

Expand All @@ -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))

Check warning on line 61 in api/v1/peers.go

View workflow job for this annotation

GitHub Actions / lint

errorf: should replace errors.New(fmt.Sprintf(...)) with fmt.Errorf(...) (revive)
}
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)
}
2 changes: 1 addition & 1 deletion multi/nodepeers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions testclients/erroring.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions testclients/sleepy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6d12fab

Please sign in to comment.