Skip to content

Commit d9a0c70

Browse files
committed
Switch golang flag's to allow for glog argument access
1 parent 702a5d5 commit d9a0c70

File tree

3 files changed

+34
-42
lines changed

3 files changed

+34
-42
lines changed

cmd/mc-router/main.go

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,24 @@ package main
22

33
import (
44
"context"
5+
"flag"
56
"fmt"
6-
"github.com/alecthomas/kingpin"
77
"github.com/itzg/mc-router/server"
88
"github.com/sirupsen/logrus"
99
"net"
1010
"os"
1111
"os/signal"
1212
"strconv"
13+
"strings"
1314
)
1415

1516
var (
16-
port = kingpin.Flag("port", "The port bound to listen for Minecraft client connections").
17-
Default("25565").Int()
18-
apiBinding = kingpin.Flag("api-binding", "The host:port bound for servicing API requests").
19-
String()
20-
mappings = kingpin.Flag("mapping", "Mapping of external hostname to internal server host:port").
21-
StringMap()
22-
versionFlag = kingpin.Flag("version", "Output version and exit").
23-
Bool()
24-
kubeConfigFile = kingpin.Flag("kube-config", "The path to a kubernetes configuration file").String()
25-
inKubeCluster = kingpin.Flag("in-kube-cluster", "Use in-cluster kubernetes config").Bool()
17+
port = flag.Int("port", 25565, "The port bound to listen for Minecraft client connections")
18+
apiBinding = flag.String("api-binding", "", "The host:port bound for servicing API requests")
19+
mappings = flag.String("mapping", "", "Comma-separated mappings of externalHostname=host:port")
20+
versionFlag = flag.Bool("version", false, "Output version and exit")
21+
kubeConfigFile = flag.String("kube-config", "", "The path to a kubernetes configuration file")
22+
inKubeCluster = flag.Bool("in-kube-cluster", false, "Use in-cluster kubernetes config")
2623
)
2724

2825
var (
@@ -36,7 +33,7 @@ func showVersion() {
3633
}
3734

3835
func main() {
39-
kingpin.Parse()
36+
flag.Parse()
4037

4138
if *versionFlag {
4239
showVersion()
@@ -48,7 +45,7 @@ func main() {
4845
c := make(chan os.Signal, 1)
4946
signal.Notify(c, os.Interrupt)
5047

51-
server.Routes.RegisterAll(*mappings)
48+
server.Routes.RegisterAll(parseMappings(*mappings))
5249

5350
server.Connector.StartAcceptingConnections(ctx, net.JoinHostPort("", strconv.Itoa(*port)))
5451

@@ -77,3 +74,19 @@ func main() {
7774
logrus.Info("Stopping")
7875
cancel()
7976
}
77+
78+
func parseMappings(val string) map[string]string {
79+
result := make(map[string]string)
80+
if val != "" {
81+
parts := strings.Split(val, ",")
82+
for _, part := range parts {
83+
keyValue := strings.Split(part, "=")
84+
if len(keyValue) == 2 {
85+
result[keyValue[0]] = keyValue[1]
86+
}
87+
logrus.WithField("part", part).Fatal("Invalid part of mapping")
88+
}
89+
}
90+
91+
return result
92+
}

glide.lock

Lines changed: 8 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

glide.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package: github.com/itzg/mc-router
22
import:
3-
- package: github.com/alecthomas/kingpin
4-
version: ^2.2.6
53
- package: github.com/gorilla/mux
64
version: ^1.6.2
75
- package: github.com/pkg/errors

0 commit comments

Comments
 (0)