From d9a0c70a31d04386e036b2fd69bc4c33cecf3918 Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Sun, 27 May 2018 15:36:01 -0500 Subject: [PATCH] Switch golang flag's to allow for glog argument access --- cmd/mc-router/main.go | 39 ++++++++++++++++++++++++++------------- glide.lock | 35 ++++++++--------------------------- glide.yaml | 2 -- 3 files changed, 34 insertions(+), 42 deletions(-) diff --git a/cmd/mc-router/main.go b/cmd/mc-router/main.go index d93a610..d5f1fe1 100644 --- a/cmd/mc-router/main.go +++ b/cmd/mc-router/main.go @@ -2,27 +2,24 @@ package main import ( "context" + "flag" "fmt" - "github.com/alecthomas/kingpin" "github.com/itzg/mc-router/server" "github.com/sirupsen/logrus" "net" "os" "os/signal" "strconv" + "strings" ) var ( - port = kingpin.Flag("port", "The port bound to listen for Minecraft client connections"). - Default("25565").Int() - apiBinding = kingpin.Flag("api-binding", "The host:port bound for servicing API requests"). - String() - mappings = kingpin.Flag("mapping", "Mapping of external hostname to internal server host:port"). - StringMap() - versionFlag = kingpin.Flag("version", "Output version and exit"). - Bool() - kubeConfigFile = kingpin.Flag("kube-config", "The path to a kubernetes configuration file").String() - inKubeCluster = kingpin.Flag("in-kube-cluster", "Use in-cluster kubernetes config").Bool() + port = flag.Int("port", 25565, "The port bound to listen for Minecraft client connections") + apiBinding = flag.String("api-binding", "", "The host:port bound for servicing API requests") + mappings = flag.String("mapping", "", "Comma-separated mappings of externalHostname=host:port") + versionFlag = flag.Bool("version", false, "Output version and exit") + kubeConfigFile = flag.String("kube-config", "", "The path to a kubernetes configuration file") + inKubeCluster = flag.Bool("in-kube-cluster", false, "Use in-cluster kubernetes config") ) var ( @@ -36,7 +33,7 @@ func showVersion() { } func main() { - kingpin.Parse() + flag.Parse() if *versionFlag { showVersion() @@ -48,7 +45,7 @@ func main() { c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt) - server.Routes.RegisterAll(*mappings) + server.Routes.RegisterAll(parseMappings(*mappings)) server.Connector.StartAcceptingConnections(ctx, net.JoinHostPort("", strconv.Itoa(*port))) @@ -77,3 +74,19 @@ func main() { logrus.Info("Stopping") cancel() } + +func parseMappings(val string) map[string]string { + result := make(map[string]string) + if val != "" { + parts := strings.Split(val, ",") + for _, part := range parts { + keyValue := strings.Split(part, "=") + if len(keyValue) == 2 { + result[keyValue[0]] = keyValue[1] + } + logrus.WithField("part", part).Fatal("Invalid part of mapping") + } + } + + return result +} diff --git a/glide.lock b/glide.lock index 5beb2c8..c3caf98 100644 --- a/glide.lock +++ b/glide.lock @@ -1,14 +1,6 @@ -hash: d0042501db8c547ec44ff6828ff8b0c7d08561d95311f4c62cf8014e6a02e97e -updated: 2018-05-26T11:09:13.8257578-05:00 +hash: 6d3afa029b5a24a153f556f8a2ca493f4f1de4c41f438d2309a32a922e2d9408 +updated: 2018-05-27T14:41:00.6804253-05:00 imports: -- name: github.com/alecthomas/kingpin - version: 947dcec5ba9c011838740e680966fd7087a71d0d -- name: github.com/alecthomas/template - version: a0175ee3bccc567396460bf5acd36800cb10c49c - subpackages: - - parse -- name: github.com/alecthomas/units - version: 2efee857e7cfd4f3d0138cc3cbb1b4966962b93a - name: github.com/davecgh/go-spew version: 782f4967f2dc4564575ca782fe2d04090b5faca8 subpackages: @@ -59,14 +51,13 @@ imports: - name: github.com/spf13/pflag version: 4c012f6dcd9546820e378d0bdda4d8fc772cdfea - name: golang.org/x/crypto - version: a3beeb748656e13e54256fd2cde19e058f41f60f + version: ab813273cd59e1333f7ae7bff5d027d4aadf528c subpackages: - ssh/terminal - name: golang.org/x/net version: 1c05540f6879653db88113bc4a2b70aec4bd491f subpackages: - context - - context/ctxhttp - http2 - http2/hpack - idna @@ -126,17 +117,10 @@ imports: - name: k8s.io/apimachinery version: 302974c03f7e50f16561ba237db776ab93594ef6 subpackages: - - pkg/api/equality - pkg/api/errors - pkg/api/meta - pkg/api/resource - - pkg/api/testing - - pkg/api/testing/fuzzer - - pkg/api/testing/roundtrip - - pkg/apimachinery - - pkg/apimachinery/announced - - pkg/apimachinery/registered - - pkg/apis/meta/fuzzer + - pkg/api/resource - pkg/apis/meta/internalversion - pkg/apis/meta/v1 - pkg/apis/meta/v1/unstructured @@ -146,6 +130,8 @@ imports: - pkg/fields - pkg/labels - pkg/runtime + - pkg/runtime + - pkg/runtime/schema - pkg/runtime/schema - pkg/runtime/serializer - pkg/runtime/serializer/json @@ -155,29 +141,24 @@ imports: - pkg/runtime/serializer/versioning - pkg/selection - pkg/types + - pkg/types - pkg/util/cache - pkg/util/clock - pkg/util/diff - pkg/util/errors - pkg/util/framer - - pkg/util/httpstream - - pkg/util/httpstream/spdy + - pkg/util/intstr - pkg/util/intstr - pkg/util/json - - pkg/util/mergepatch - pkg/util/net - - pkg/util/remotecommand - pkg/util/runtime - pkg/util/sets - - pkg/util/strategicpatch - pkg/util/validation - pkg/util/validation/field - pkg/util/wait - pkg/util/yaml - pkg/version - pkg/watch - - third_party/forked/golang/json - - third_party/forked/golang/netutil - third_party/forked/golang/reflect - name: k8s.io/client-go version: 23781f4d6632d88e869066eaebb743857aa1ef9b diff --git a/glide.yaml b/glide.yaml index 7228ea6..343d0c2 100644 --- a/glide.yaml +++ b/glide.yaml @@ -1,7 +1,5 @@ package: github.com/itzg/mc-router import: -- package: github.com/alecthomas/kingpin - version: ^2.2.6 - package: github.com/gorilla/mux version: ^1.6.2 - package: github.com/pkg/errors