Skip to content

Commit

Permalink
refactor: run gofumpt on code
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Stewart <[email protected]>
  • Loading branch information
paralin committed Jan 25, 2024
1 parent daad194 commit 0a4cdd5
Show file tree
Hide file tree
Showing 31 changed files with 97 additions and 77 deletions.
2 changes: 1 addition & 1 deletion cli/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func (a *ClientArgs) LoadOrGenerateIdentifyKey() ([]byte, crypto.PrivKey, error)
if err != nil {
return nil, nil, err
}
if err := os.WriteFile(a.IdentifyKeyPath, dat, 0600); err != nil {
if err := os.WriteFile(a.IdentifyKeyPath, dat, 0o600); err != nil {
return nil, nil, err
}
}
Expand Down
1 change: 0 additions & 1 deletion cli/daemonflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ func (a *DaemonArgs) BuildFlags() []cli.Flag {
Destination: &a.Pubsub,
},
}

}

// ApplyFactories applies any extra factories necessary on top of the core set.
Expand Down
2 changes: 1 addition & 1 deletion cli/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func writeIfNotExists(outPath string, input io.Reader) error {
if !os.IsNotExist(err) {
return errors.Wrap(os.ErrExist, outPath)
}
of, err = os.OpenFile(outPath, os.O_CREATE|os.O_RDWR, 0600)
of, err = os.OpenFile(outPath, os.O_CREATE|os.O_RDWR, 0o600)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/bifrost/cmd_daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func runDaemon(c *cli.Context) error {
if err != nil {
return errors.Wrap(err, "marshal config")
}
err = os.WriteFile(daemonFlags.ConfigPath, confDat, 0644)
err = os.WriteFile(daemonFlags.ConfigPath, confDat, 0o644)
if err != nil {
return errors.Wrap(err, "write config file")
}
Expand Down
6 changes: 2 additions & 4 deletions daemon/api/api_pubsub_subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ import (
"github.com/pkg/errors"
)

var (
// acquirePeerTimeout is the timeout for acquiring private key
acquirePeerTimeout = time.Second * 10
)
// acquirePeerTimeout is the timeout for acquiring private key
var acquirePeerTimeout = time.Second * 10

// Subscribe subscribes to a pubsub channel.
//
Expand Down
6 changes: 4 additions & 2 deletions examples/nats-host/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ import (

var logTrace = false

var addPeer = tests.AddPeer
var initSimulator = tests.InitSimulator
var (
addPeer = tests.AddPeer
initSimulator = tests.InitSimulator
)

var privKeyPath string

Expand Down
6 changes: 4 additions & 2 deletions examples/nats-host/nats-single/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import (
"github.com/aperturerobotics/controllerbus/controller"
)

var addPeer = tests.AddPeer
var initSimulator = tests.InitSimulator
var (
addPeer = tests.AddPeer
initSimulator = tests.InitSimulator
)

var privKeyPath string

Expand Down
6 changes: 4 additions & 2 deletions examples/udp-link/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import (
"github.com/sirupsen/logrus"
)

var log = logrus.New()
var le = logrus.NewEntry(log)
var (
log = logrus.New()
le = logrus.NewEntry(log)
)

func init() {
log.SetLevel(logrus.DebugLevel)
Expand Down
6 changes: 4 additions & 2 deletions examples/websocket-browser-link/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import (
"github.com/sirupsen/logrus"
)

var log = logrus.New()
var le = logrus.NewEntry(log)
var (
log = logrus.New()
le = logrus.NewEntry(log)
)

func init() {
log.SetLevel(logrus.DebugLevel)
Expand Down
10 changes: 6 additions & 4 deletions examples/websocket-browser-link/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import (
"github.com/sirupsen/logrus"
)

var log = logrus.New()
var le = logrus.NewEntry(log)
var localPrivKey crypto.PrivKey
var localPeerID peer.ID
var (
log = logrus.New()
le = logrus.NewEntry(log)
localPrivKey crypto.PrivKey
localPeerID peer.ID
)

func init() {
log.SetLevel(logrus.DebugLevel)
Expand Down
1 change: 0 additions & 1 deletion http/log/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func TestDoRequest(t *testing.T) {
client := &http.Client{}
req, _ := http.NewRequest("GET", ts.URL, nil)
resp, err := DoRequest(entry, client, req, true)

if err != nil {
t.Errorf("Expected no error, got %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion keypem/keyfile/keyfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func OpenOrWritePrivKey(le *logrus.Entry, privKeyPath string) (crypto.PrivKey, e
if err != nil {
return privKey, err
}
if err := os.WriteFile(privKeyPath, dat, 0600); err != nil {
if err := os.WriteFile(privKeyPath, dat, 0o600); err != nil {
return privKey, err
}
if le != nil {
Expand Down
3 changes: 1 addition & 2 deletions peer/controller/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
)

// Factory constructs a Peer controller.
type Factory struct {
}
type Factory struct{}

// NewFactory builds a peer controller factory.
func NewFactory() *Factory {
Expand Down
3 changes: 1 addition & 2 deletions pubsub/nats/auth-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import (
)

// clientAuth authenticates client connections.
type clientAuth struct {
}
type clientAuth struct{}

func newClientAuth() *clientAuth {
return &clientAuth{}
Expand Down
3 changes: 1 addition & 2 deletions pubsub/nats/auth-router.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import (
)

// routerAuth authenticates client connections.
type routerAuth struct {
}
type routerAuth struct{}

func newRouterAuth() *routerAuth {
return &routerAuth{}
Expand Down
3 changes: 1 addition & 2 deletions pubsub/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ type PubSub interface {

// PubSubHandler manages a PubSub and receives event callbacks.
// This is typically fulfilled by the PubSub controller.
type PubSubHandler interface {
}
type PubSubHandler interface{}

// PeerLinkTuple is the peer-id link-id tuple.
type PeerLinkTuple struct {
Expand Down
6 changes: 2 additions & 4 deletions pubsub/util/pubmessage/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@ package pubmessage

import "errors"

var (
// ErrInvalidChannelID is returned for an invalid inner channel ID.
ErrInvalidChannelID = errors.New("invalid or empty channel id on pubmessage")
)
// ErrInvalidChannelID is returned for an invalid inner channel ID.
var ErrInvalidChannelID = errors.New("invalid or empty channel id on pubmessage")
6 changes: 4 additions & 2 deletions rpc/access/client-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,7 @@ func (c *ClientController) Close() error {
}

// _ is a type assertion
var _ controller.Controller = ((*ClientController)(nil))
var _ AccessClientFunc = ((*ClientController)(nil)).AccessClient
var (
_ controller.Controller = ((*ClientController)(nil))
_ AccessClientFunc = ((*ClientController)(nil)).AccessClient
)
6 changes: 2 additions & 4 deletions signaling/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@ package signaling

import "errors"

var (
// ErrEmptySignalingID is returned if the signaling id cannot be empty.
ErrEmptySignalingID = errors.New("signaling id cannot be empty")
)
// ErrEmptySignalingID is returned if the signaling id cannot be empty.
var ErrEmptySignalingID = errors.New("signaling id cannot be empty")
6 changes: 4 additions & 2 deletions signaling/rpc/server/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,13 @@ func (s *Server) Session(strm signaling.SRPCSignaling_SessionStream) error {
var err error
if currOpen != nil {
err = strm.Send(&signaling.SessionResponse{
Body: &signaling.SessionResponse_Opened{Opened: *currOpen}},
Body: &signaling.SessionResponse_Opened{Opened: *currOpen},
},
)
} else {
err = strm.Send(&signaling.SessionResponse{
Body: &signaling.SessionResponse_Closed{Closed: true}},
Body: &signaling.SessionResponse_Closed{Closed: true},
},
)
}
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions sim/tests/bifrost/bifrost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ package bifrost

import "github.com/aperturerobotics/bifrost/sim/tests"

var addPeer = tests.AddPeer
var initSimulator = tests.InitSimulator
var (
addPeer = tests.AddPeer
initSimulator = tests.InitSimulator
)
6 changes: 4 additions & 2 deletions sim/tests/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (
"github.com/sirupsen/logrus"
)

var addPeer = AddPeer
var initSimulator = InitSimulator
var (
addPeer = AddPeer
initSimulator = InitSimulator
)

func TestInitSimulator(t *testing.T) {
ctx, ctxCancel := context.WithCancel(context.Background())
Expand Down
1 change: 0 additions & 1 deletion stream/api/rpc/rpc_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ func (n *NetConn) RemoteAddr() net.Addr {
}

return peer.NewNetAddr(n.remotePeerID)

}

// SetDeadline sets the read and write deadlines associated
Expand Down
3 changes: 1 addition & 2 deletions stream/drpc/e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import (
const ProtocolID protocol.ID = "bifrost/stream/drpc/e2e"

// Server is the e2e server.
type Server struct {
}
type Server struct{}

// NewServer constructs the server.
func NewServer() *Server {
Expand Down
8 changes: 3 additions & 5 deletions transport/common/kcp/buf_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import (
"sync"
)

var (
// global packet buffer
// shared among sending/receiving
xmitBuf sync.Pool
)
// global packet buffer
// shared among sending/receiving
var xmitBuf sync.Pool

func init() {
xmitBuf.New = func() interface{} {
Expand Down
2 changes: 0 additions & 2 deletions transport/controller/mounted-stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,11 @@ func (m *mountedStream) GetStream() stream.Stream {
// GetProtocolID returns the protocol ID of the stream.
func (m *mountedStream) GetProtocolID() protocol.ID {
return m.protocolID

}

// GetOpenOpts returns the options used to open the stream.
func (m *mountedStream) GetOpenOpts() stream.OpenOpts {
return m.strmOpenOpts

}

// GetPeerID returns the peer ID for the other end of the stream.
Expand Down
1 change: 1 addition & 0 deletions util/blockcrypt/crypt/crypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func (c *salsa20BlockCrypt) Encrypt(dst, src []byte) {
salsa20.XORKeyStream(dst[8:], src[8:], src[:8], &c.key)
copy(dst[:8], src[:8])
}

func (c *salsa20BlockCrypt) Decrypt(dst, src []byte) {
salsa20.XORKeyStream(dst[8:], src[8:], src[:8], &c.key)
copy(dst[:8], src[:8])
Expand Down
1 change: 0 additions & 1 deletion util/confparse/protocol_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ func ParseProtocolID(protocolID string, allowEmpty bool) (protocol.ID, error) {
return "", err
}
return id, nil

}

// ParseProtocolIDs parses a list of peer IDs.
Expand Down
42 changes: 28 additions & 14 deletions util/extra25519/lo25519.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,49 @@ package extra25519
// The list was copied from https://github.com/jedisct1/libsodium/blob/141288535127c22162944e12fcadb8bc269671cc/src/libsodium/crypto_core/ed25519/ref10/ed25519_ref10.c
var edBlacklist = [7][32]byte{
/* 0 (order 4) */
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
/* 1 (order 1) */
{0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
{
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
/* 2707385501144840649318225287225658788936804267575313519463743609750303402022
(order 8) */
{0x26, 0xe8, 0x95, 0x8f, 0xc2, 0xb2, 0x27, 0xb0, 0x45, 0xc3, 0xf4,
{
0x26, 0xe8, 0x95, 0x8f, 0xc2, 0xb2, 0x27, 0xb0, 0x45, 0xc3, 0xf4,
0x89, 0xf2, 0xef, 0x98, 0xf0, 0xd5, 0xdf, 0xac, 0x05, 0xd3, 0xc6,
0x33, 0x39, 0xb1, 0x38, 0x02, 0x88, 0x6d, 0x53, 0xfc, 0x05},
0x33, 0x39, 0xb1, 0x38, 0x02, 0x88, 0x6d, 0x53, 0xfc, 0x05,
},
/* 55188659117513257062467267217118295137698188065244968500265048394206261417927
(order 8) */
{0xc7, 0x17, 0x6a, 0x70, 0x3d, 0x4d, 0xd8, 0x4f, 0xba, 0x3c, 0x0b,
{
0xc7, 0x17, 0x6a, 0x70, 0x3d, 0x4d, 0xd8, 0x4f, 0xba, 0x3c, 0x0b,
0x76, 0x0d, 0x10, 0x67, 0x0f, 0x2a, 0x20, 0x53, 0xfa, 0x2c, 0x39,
0xcc, 0xc6, 0x4e, 0xc7, 0xfd, 0x77, 0x92, 0xac, 0x03, 0x7a},
0xcc, 0xc6, 0x4e, 0xc7, 0xfd, 0x77, 0x92, 0xac, 0x03, 0x7a,
},
/* p-1 (order 2) */
{0xec, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
{
0xec, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f},
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f,
},
/* p (=0, order 4) */
{0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
{
0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f},
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f,
},
/* p+1 (=1, order 1) */
{0xee, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
{
0xee, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f},
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f,
},
}

// IsLowOrder checks if the passed group element is of low order.
Expand Down
12 changes: 8 additions & 4 deletions util/labels/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
"github.com/pkg/errors"
)

const dns1123LabelFmt string = "[a-z0-9]([-a-z0-9]*[a-z0-9])?"
const dns1123LabelErrMsg string = "a DNS-1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character"
const (
dns1123LabelFmt string = "[a-z0-9]([-a-z0-9]*[a-z0-9])?"
dns1123LabelErrMsg string = "a DNS-1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character"
)

// DNS1123LabelMaxLength is a label's max length in DNS (RFC 1123)
const DNS1123LabelMaxLength int = 63
Expand All @@ -32,8 +34,10 @@ func ValidateDNSLabel(id string) error {
return nil
}

const dns1123SubdomainFmt string = dns1123LabelFmt + "(\\." + dns1123LabelFmt + ")*"
const dns1123SubdomainErrMsg string = "a DNS-1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character"
const (
dns1123SubdomainFmt string = dns1123LabelFmt + "(\\." + dns1123LabelFmt + ")*"
dns1123SubdomainErrMsg string = "a DNS-1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character"
)

// DNS1123SubdomainMaxLength is a subdomain's max length in DNS (RFC 1123)
const DNS1123SubdomainMaxLength int = 253
Expand Down
Loading

0 comments on commit 0a4cdd5

Please sign in to comment.