@@ -2,27 +2,24 @@ package main
22
33import (
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
1516var (
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
2825var (
@@ -36,7 +33,7 @@ func showVersion() {
3633}
3734
3835func 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+ }
0 commit comments