From 0a4cdd598260ce7f3b59973cb1a5ec58485ea2b4 Mon Sep 17 00:00:00 2001 From: Christian Stewart Date: Wed, 24 Jan 2024 20:13:14 -0800 Subject: [PATCH] refactor: run gofumpt on code Signed-off-by: Christian Stewart --- cli/client.go | 2 +- cli/daemonflags.go | 1 - cli/util/util.go | 2 +- cmd/bifrost/cmd_daemon.go | 2 +- daemon/api/api_pubsub_subscribe.go | 6 +-- examples/nats-host/main.go | 6 ++- examples/nats-host/nats-single/main.go | 6 ++- examples/udp-link/main.go | 6 ++- .../websocket-browser-link/common/common.go | 6 ++- .../websocket-browser-link/server/server.go | 10 +++-- http/log/client_test.go | 1 - keypem/keyfile/keyfile.go | 2 +- peer/controller/factory.go | 3 +- pubsub/nats/auth-client.go | 3 +- pubsub/nats/auth-router.go | 3 +- pubsub/pubsub.go | 3 +- pubsub/util/pubmessage/errors.go | 6 +-- rpc/access/client-controller.go | 6 ++- signaling/errors.go | 6 +-- signaling/rpc/server/session.go | 6 ++- sim/tests/bifrost/bifrost_test.go | 6 ++- sim/tests/common_test.go | 6 ++- stream/api/rpc/rpc_conn.go | 1 - stream/drpc/e2e/e2e.go | 3 +- transport/common/kcp/buf_pool.go | 8 ++-- transport/controller/mounted-stream.go | 2 - util/blockcrypt/crypt/crypt.go | 1 + util/confparse/protocol_id.go | 1 - util/extra25519/lo25519.go | 42 ++++++++++++------- util/labels/labels.go | 12 ++++-- util/scrc/scrc.go | 6 ++- 31 files changed, 97 insertions(+), 77 deletions(-) diff --git a/cli/client.go b/cli/client.go index 8b90090a..1e6ce5db 100644 --- a/cli/client.go +++ b/cli/client.go @@ -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 } } diff --git a/cli/daemonflags.go b/cli/daemonflags.go index cf950f68..17738773 100644 --- a/cli/daemonflags.go +++ b/cli/daemonflags.go @@ -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. diff --git a/cli/util/util.go b/cli/util/util.go index 3742a00b..0fe40713 100644 --- a/cli/util/util.go +++ b/cli/util/util.go @@ -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 } diff --git a/cmd/bifrost/cmd_daemon.go b/cmd/bifrost/cmd_daemon.go index 65344d65..dd92e72c 100644 --- a/cmd/bifrost/cmd_daemon.go +++ b/cmd/bifrost/cmd_daemon.go @@ -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") } diff --git a/daemon/api/api_pubsub_subscribe.go b/daemon/api/api_pubsub_subscribe.go index 22195d41..1e3b2e89 100644 --- a/daemon/api/api_pubsub_subscribe.go +++ b/daemon/api/api_pubsub_subscribe.go @@ -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. // diff --git a/examples/nats-host/main.go b/examples/nats-host/main.go index 0b4c8215..88d61779 100644 --- a/examples/nats-host/main.go +++ b/examples/nats-host/main.go @@ -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 diff --git a/examples/nats-host/nats-single/main.go b/examples/nats-host/nats-single/main.go index 6688ceac..a4d2f54b 100644 --- a/examples/nats-host/nats-single/main.go +++ b/examples/nats-host/nats-single/main.go @@ -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 diff --git a/examples/udp-link/main.go b/examples/udp-link/main.go index 64562c7c..85b6b154 100644 --- a/examples/udp-link/main.go +++ b/examples/udp-link/main.go @@ -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) diff --git a/examples/websocket-browser-link/common/common.go b/examples/websocket-browser-link/common/common.go index 451bd709..96292f97 100644 --- a/examples/websocket-browser-link/common/common.go +++ b/examples/websocket-browser-link/common/common.go @@ -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) diff --git a/examples/websocket-browser-link/server/server.go b/examples/websocket-browser-link/server/server.go index 305de7b3..48b282ff 100644 --- a/examples/websocket-browser-link/server/server.go +++ b/examples/websocket-browser-link/server/server.go @@ -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) diff --git a/http/log/client_test.go b/http/log/client_test.go index 36b39a3a..8a0b7f7f 100644 --- a/http/log/client_test.go +++ b/http/log/client_test.go @@ -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) } diff --git a/keypem/keyfile/keyfile.go b/keypem/keyfile/keyfile.go index da60f8da..60a99a75 100644 --- a/keypem/keyfile/keyfile.go +++ b/keypem/keyfile/keyfile.go @@ -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 { diff --git a/peer/controller/factory.go b/peer/controller/factory.go index 02e2a66d..7f51f79e 100644 --- a/peer/controller/factory.go +++ b/peer/controller/factory.go @@ -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 { diff --git a/pubsub/nats/auth-client.go b/pubsub/nats/auth-client.go index 7f3d1d15..311354f6 100644 --- a/pubsub/nats/auth-client.go +++ b/pubsub/nats/auth-client.go @@ -5,8 +5,7 @@ import ( ) // clientAuth authenticates client connections. -type clientAuth struct { -} +type clientAuth struct{} func newClientAuth() *clientAuth { return &clientAuth{} diff --git a/pubsub/nats/auth-router.go b/pubsub/nats/auth-router.go index 7ebdba41..cf63f381 100644 --- a/pubsub/nats/auth-router.go +++ b/pubsub/nats/auth-router.go @@ -5,8 +5,7 @@ import ( ) // routerAuth authenticates client connections. -type routerAuth struct { -} +type routerAuth struct{} func newRouterAuth() *routerAuth { return &routerAuth{} diff --git a/pubsub/pubsub.go b/pubsub/pubsub.go index ea860304..9e32dadb 100644 --- a/pubsub/pubsub.go +++ b/pubsub/pubsub.go @@ -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 { diff --git a/pubsub/util/pubmessage/errors.go b/pubsub/util/pubmessage/errors.go index 9c034c0e..d8c66775 100644 --- a/pubsub/util/pubmessage/errors.go +++ b/pubsub/util/pubmessage/errors.go @@ -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") diff --git a/rpc/access/client-controller.go b/rpc/access/client-controller.go index fac58d81..89a953c4 100644 --- a/rpc/access/client-controller.go +++ b/rpc/access/client-controller.go @@ -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 +) diff --git a/signaling/errors.go b/signaling/errors.go index 27d2442a..cc1f7cbf 100644 --- a/signaling/errors.go +++ b/signaling/errors.go @@ -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") diff --git a/signaling/rpc/server/session.go b/signaling/rpc/server/session.go index 05960fe8..e827acc0 100644 --- a/signaling/rpc/server/session.go +++ b/signaling/rpc/server/session.go @@ -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 { diff --git a/sim/tests/bifrost/bifrost_test.go b/sim/tests/bifrost/bifrost_test.go index cb81df16..3537d4f2 100644 --- a/sim/tests/bifrost/bifrost_test.go +++ b/sim/tests/bifrost/bifrost_test.go @@ -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 +) diff --git a/sim/tests/common_test.go b/sim/tests/common_test.go index f997835a..96d09a5f 100644 --- a/sim/tests/common_test.go +++ b/sim/tests/common_test.go @@ -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()) diff --git a/stream/api/rpc/rpc_conn.go b/stream/api/rpc/rpc_conn.go index 68f22177..99e69074 100644 --- a/stream/api/rpc/rpc_conn.go +++ b/stream/api/rpc/rpc_conn.go @@ -82,7 +82,6 @@ func (n *NetConn) RemoteAddr() net.Addr { } return peer.NewNetAddr(n.remotePeerID) - } // SetDeadline sets the read and write deadlines associated diff --git a/stream/drpc/e2e/e2e.go b/stream/drpc/e2e/e2e.go index 9a9f88b2..ea4f1330 100644 --- a/stream/drpc/e2e/e2e.go +++ b/stream/drpc/e2e/e2e.go @@ -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 { diff --git a/transport/common/kcp/buf_pool.go b/transport/common/kcp/buf_pool.go index fc989bd5..47fc29a3 100644 --- a/transport/common/kcp/buf_pool.go +++ b/transport/common/kcp/buf_pool.go @@ -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{} { diff --git a/transport/controller/mounted-stream.go b/transport/controller/mounted-stream.go index 27a57e55..7a735eaf 100644 --- a/transport/controller/mounted-stream.go +++ b/transport/controller/mounted-stream.go @@ -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. diff --git a/util/blockcrypt/crypt/crypt.go b/util/blockcrypt/crypt/crypt.go index 609d6978..2762c3ae 100644 --- a/util/blockcrypt/crypt/crypt.go +++ b/util/blockcrypt/crypt/crypt.go @@ -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]) diff --git a/util/confparse/protocol_id.go b/util/confparse/protocol_id.go index ad27dabb..cc336b53 100644 --- a/util/confparse/protocol_id.go +++ b/util/confparse/protocol_id.go @@ -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. diff --git a/util/extra25519/lo25519.go b/util/extra25519/lo25519.go index 268237ba..28244036 100644 --- a/util/extra25519/lo25519.go +++ b/util/extra25519/lo25519.go @@ -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. diff --git a/util/labels/labels.go b/util/labels/labels.go index da8245b7..1fcf0fe1 100644 --- a/util/labels/labels.go +++ b/util/labels/labels.go @@ -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 @@ -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 diff --git a/util/scrc/scrc.go b/util/scrc/scrc.go index 81c73229..94eb4483 100644 --- a/util/scrc/scrc.go +++ b/util/scrc/scrc.go @@ -6,8 +6,10 @@ import ( "sync" ) -var h64Mtx sync.Mutex -var h64 hash.Hash64 +var ( + h64Mtx sync.Mutex + h64 hash.Hash64 +) func init() { h64 = crc64.New(crc64.MakeTable(crc64.ECMA))