Switch golang flag's to allow for glog argument access
This commit is contained in:
+26
-13
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user