Created
October 26, 2017 00:23
-
-
Save Pheric/6f6c34c22ca26b110e0e3fe16bb14270 to your computer and use it in GitHub Desktop.
Golang Spigot BungeeCord config file parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"gopkg.in/yaml.v2" | |
"log" | |
) | |
type BungeeConf struct { | |
IpForward bool `yaml:"ip_forward"` | |
NetworkCompressionThreshold int `yaml:"network_compression_threshold"` | |
Stats string `yaml:"stats"` | |
Groups map[string][]string `yaml:"groups"` | |
Servers map[string]Server `yaml:"servers"` | |
Timeout int `yaml:"timeout"` | |
PlayerLimit int `yaml:"player_limit"` | |
Listeners []Listener `yaml:"listeners"` | |
PreventProxyConnections bool `yaml:"prevent_proxy_connections"` | |
Permissions map[string][]string `yaml:"permissions"` | |
OnlineMode bool `yaml:"online_mode"` | |
LogCommands bool `yaml:"log_commands"` | |
DisabledCommands []string `yaml:"disabled_commands"` | |
ConnectionThrottle int `yaml:"connection_throttle"` | |
} | |
type Server struct { | |
Motd string `yaml:"motd"` | |
Address string `yaml:"address"` | |
Restricted bool `yaml:"restricted"` | |
} | |
type Listener struct { | |
QueryPort int `yaml:"query_port"` | |
Motd string `yaml:"motd"` | |
TabList string `yaml:"tab_list"` | |
QueryEnabled bool `yaml:"query_enabled"` | |
ProxyProtocol bool `yaml:"proxy_protocol"` | |
ForcedHosts map[string]string `yaml:"forced_hosts"` | |
PingPassthrough bool `yaml:"ping_passthrough"` | |
Priorities []string `yaml:"priorities"` | |
BindLocalAddress bool `yaml:"bind_local_address"` | |
Host string `yaml:"host"` | |
MaxPlayers int `yaml:"max_players"` | |
TabSize int `yaml:"tab_size"` | |
ForceDefaultServer bool `yaml:"force_default_server"` | |
} | |
func ParseConfig(data []byte) *BungeeConf { | |
conf := BungeeConf{} | |
if err := yaml.Unmarshal(data, &conf); err != nil { | |
log.Fatalf("Failed to parse input: %v", err) | |
} | |
return &conf | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment