From 1f5ac0b49d5cf3836e502235ea19345a92bc0e8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vorburger=20=E2=9B=91=EF=B8=8F?= Date: Sun, 12 Dec 2021 01:20:19 +0100 Subject: [PATCH] Very minor clean-ups (import re-ordering by automated tooling) (#28) --- cmd/mc-router/metrics.go | 5 +++-- mcproto/read.go | 9 +++++---- mcproto/read_test.go | 3 ++- server/api_server.go | 3 ++- server/connector.go | 10 +++++----- server/k8s.go | 9 +++++---- server/k8s_test.go | 3 ++- server/routes.go | 13 +++++-------- server/routes_test.go | 3 ++- 9 files changed, 31 insertions(+), 27 deletions(-) diff --git a/cmd/mc-router/metrics.go b/cmd/mc-router/metrics.go index e3c9999..6798db0 100644 --- a/cmd/mc-router/metrics.go +++ b/cmd/mc-router/metrics.go @@ -4,6 +4,9 @@ import ( "context" "errors" "fmt" + "strings" + "time" + kitlogrus "github.com/go-kit/kit/log/logrus" discardMetrics "github.com/go-kit/kit/metrics/discard" expvarMetrics "github.com/go-kit/kit/metrics/expvar" @@ -11,8 +14,6 @@ import ( influx "github.com/influxdata/influxdb1-client/v2" "github.com/itzg/mc-router/server" "github.com/sirupsen/logrus" - "strings" - "time" ) type MetricsBuilder interface { diff --git a/mcproto/read.go b/mcproto/read.go index 9eb5118..77bd20a 100644 --- a/mcproto/read.go +++ b/mcproto/read.go @@ -4,14 +4,15 @@ import ( "bufio" "bytes" "encoding/binary" - "github.com/pkg/errors" - "github.com/sirupsen/logrus" - "golang.org/x/text/encoding/unicode" - "golang.org/x/text/transform" "io" "net" "strings" "time" + + "github.com/pkg/errors" + "github.com/sirupsen/logrus" + "golang.org/x/text/encoding/unicode" + "golang.org/x/text/transform" ) func ReadPacket(reader io.Reader, addr net.Addr, state State) (*Packet, error) { diff --git a/mcproto/read_test.go b/mcproto/read_test.go index ed2c208..d8f0096 100644 --- a/mcproto/read_test.go +++ b/mcproto/read_test.go @@ -2,9 +2,10 @@ package mcproto import ( "bytes" + "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "testing" ) func TestReadVarInt(t *testing.T) { diff --git a/server/api_server.go b/server/api_server.go index 12725f2..be9528a 100644 --- a/server/api_server.go +++ b/server/api_server.go @@ -2,9 +2,10 @@ package server import ( "expvar" + "net/http" + "github.com/gorilla/mux" "github.com/sirupsen/logrus" - "net/http" ) var apiRoutes = mux.NewRouter() diff --git a/server/connector.go b/server/connector.go index d6a2939..455ae5a 100644 --- a/server/connector.go +++ b/server/connector.go @@ -3,15 +3,16 @@ package server import ( "bytes" "context" + "io" + "net" + "strconv" + "time" + "github.com/go-kit/kit/metrics" "github.com/itzg/mc-router/mcproto" "github.com/juju/ratelimit" "github.com/pires/go-proxyproto" "github.com/sirupsen/logrus" - "io" - "net" - "strconv" - "time" ) const ( @@ -243,7 +244,6 @@ func (c *connectorImpl) findAndConnectBackend(ctx context.Context, frontendConn } c.pumpConnections(ctx, frontendConn, backendConn) - return } func (c *connectorImpl) pumpConnections(ctx context.Context, frontendConn, backendConn net.Conn) { diff --git a/server/k8s.go b/server/k8s.go index b4d48c5..26f5ab8 100644 --- a/server/k8s.go +++ b/server/k8s.go @@ -1,17 +1,18 @@ package server import ( + "net" + "strconv" + "strings" + "github.com/pkg/errors" "github.com/sirupsen/logrus" - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" "k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/clientcmd" - "net" - "strconv" - "strings" ) const ( diff --git a/server/k8s_test.go b/server/k8s_test.go index 195a4c9..e5e5918 100644 --- a/server/k8s_test.go +++ b/server/k8s_test.go @@ -2,10 +2,11 @@ package server import ( "encoding/json" + "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" v1 "k8s.io/api/core/v1" - "testing" ) func TestK8sWatcherImpl_handleAddThenUpdate(t *testing.T) { diff --git a/server/routes.go b/server/routes.go index d103873..ef32475 100644 --- a/server/routes.go +++ b/server/routes.go @@ -2,11 +2,12 @@ package server import ( "encoding/json" - "github.com/gorilla/mux" - "github.com/sirupsen/logrus" "net/http" "strings" "sync" + + "github.com/gorilla/mux" + "github.com/sirupsen/logrus" ) func init() { @@ -134,16 +135,12 @@ func (r *routesImpl) FindBackendForServerAddress(serverAddress string) (string, address := strings.ToLower(addressParts[0]) - if r.mappings == nil { - return r.defaultRoute, address - } else { - + if r.mappings != nil { if route, exists := r.mappings[address]; exists { return route, address - } else { - return r.defaultRoute, address } } + return r.defaultRoute, address } func (r *routesImpl) GetMappings() map[string]string { diff --git a/server/routes_test.go b/server/routes_test.go index 57a5f16..0c5b778 100644 --- a/server/routes_test.go +++ b/server/routes_test.go @@ -1,8 +1,9 @@ package server import ( - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func Test_routesImpl_FindBackendForServerAddress(t *testing.T) {