1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
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"`
}
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,
},
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
}
func SaveDefault(path string) error {
cfg := Default()
data, err := yaml.Marshal(cfg)
if err != nil {
return err
}
return os.WriteFile(path, data, 0644)
}
|