Allow --mapping argument to be repeated or comma-separated

This commit is contained in:
Geoff Bourne 2021-08-10 16:54:23 -05:00
parent 226f821598
commit 7779b866d1

View File

@ -29,17 +29,17 @@ type MetricsBackendConfig struct {
} }
type Config struct { type Config struct {
Port int `default:"25565" usage:"The [port] bound to listen for Minecraft client connections"` Port int `default:"25565" usage:"The [port] bound to listen for Minecraft client connections"`
Mapping string `usage:"Comma-separated mappings of externalHostname=host:port"` Mapping []string `usage:"Comma-separated or repeated mappings of externalHostname=host:port"`
ApiBinding string `usage:"The [host:port] bound for servicing API requests"` ApiBinding string `usage:"The [host:port] bound for servicing API requests"`
Version bool `usage:"Output version and exit"` Version bool `usage:"Output version and exit"`
CpuProfile string `usage:"Enables CPU profiling and writes to given path"` CpuProfile string `usage:"Enables CPU profiling and writes to given path"`
Debug bool `usage:"Enable debug logs"` Debug bool `usage:"Enable debug logs"`
ConnectionRateLimit int `default:"1" usage:"Max number of connections to allow per second"` ConnectionRateLimit int `default:"1" usage:"Max number of connections to allow per second"`
KubeDiscovery bool `usage:"Enables discovery of annotated kubernetes services"` KubeDiscovery bool `usage:"Enables discovery of annotated kubernetes services"`
InKubeCluster bool `usage:"Use in-cluster kubernetes config"` InKubeCluster bool `usage:"Use in-cluster kubernetes config"`
KubeConfig string `usage:"The path to a kubernetes configuration file"` KubeConfig string `usage:"The path to a kubernetes configuration file"`
MetricsBackend string `default:"discard" usage:"Backend to use for metrics exposure/publishing: discard,expvar,influxdb"` MetricsBackend string `default:"discard" usage:"Backend to use for metrics exposure/publishing: discard,expvar,influxdb"`
MetricsBackendConfig MetricsBackendConfig MetricsBackendConfig MetricsBackendConfig
} }
@ -137,17 +137,14 @@ func main() {
logrus.Info("Stopping") logrus.Info("Stopping")
} }
func parseMappings(val string) map[string]string { func parseMappings(vals []string) map[string]string {
result := make(map[string]string) result := make(map[string]string)
if val != "" { for _, part := range vals {
parts := strings.Split(val, ",") keyValue := strings.Split(part, "=")
for _, part := range parts { if len(keyValue) == 2 {
keyValue := strings.Split(part, "=") result[keyValue[0]] = keyValue[1]
if len(keyValue) == 2 { } else {
result[keyValue[0]] = keyValue[1] logrus.WithField("part", part).Fatal("Invalid part of mapping")
} else {
logrus.WithField("part", part).Fatal("Invalid part of mapping")
}
} }
} }