package config import ( "os" "gopkg.in/yaml.v3" ) type Config struct { Game GameConfig `yaml:"game"` Telnet TelnetConfig `yaml:"telnet"` HTTP HTTPConfig `yaml:"http"` HTTPS HTTPSConfig `yaml:"https"` } type GameConfig struct { TickLength int `yaml:"tick_length"` GameSpeed float64 `yaml:"game_speed"` } type TelnetConfig struct { Enabled bool `yaml:"enabled"` Port int `yaml:"port"` } type HTTPConfig struct { Enabled bool `yaml:"enabled"` Port int `yaml:"port"` } type HTTPSConfig struct { Enabled bool `yaml:"enabled"` Port int `yaml:"port"` CertFile string `yaml:"cert_file"` KeyFile string `yaml:"key_file"` } func Default() *Config { return &Config{ Game: GameConfig{ TickLength: 600, GameSpeed: 1.0, }, Telnet: TelnetConfig{ Enabled: true, Port: 4000, }, HTTP: HTTPConfig{ Enabled: false, Port: 8080, }, HTTPS: HTTPSConfig{ Enabled: false, Port: 8443, }, } } func Load(path string) (*Config, error) { data, err := os.ReadFile(path) if err != nil { return nil, err } cfg := Default() if err := yaml.Unmarshal(data, cfg); err != nil { return nil, err } return cfg, nil }