-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
79 lines (69 loc) · 1.7 KB
/
config.go
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
77
78
79
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"go.uber.org/zap/zapcore"
)
type gameserverConfig struct {
Instance string `json:"instance"`
Log struct {
Level zapcore.Level `json:"level"`
Config string `json:"config"`
Colored bool `json:"colored"`
File struct {
Active bool `json:"active"`
} `json:"file"`
Sentry struct {
Active bool `json:"active"`
DSN string `json:"dsn"`
} `json:"sentry"`
} `json:"log"`
Database struct {
MariaDB struct {
Host string `json:"host"`
User string `json:"user"`
Password string `json:"password"`
Name string `json:"name"`
} `json:"mariadb"`
} `json:"database"`
Network struct {
TCP struct {
Addr string `json:"addr"`
} `json:"tcp"`
WS struct {
Addr string `json:"addr"`
ValidOrigin string `json:"valid_origin"`
TLS struct {
Active bool `json:"active"`
Cert string `json:"cert"`
PKey string `json:"pkey"`
} `json:"tls"`
Flags struct {
Debug bool `json:"debug"`
Stats bool `json:"stats"`
} `json:"flags"`
} `json:"ws"`
} `json:"network"`
Battle struct {
RoundID int `json:"round_id"`
AvatarPictureURL string `json:"avatar_picture_url"`
} `json:"battle"`
}
// loadConfig takes a path to a configfile and returns a
// pointer to a gameserverConfig
func loadConfig(path string) *gameserverConfig {
f, err := ioutil.ReadFile(path) /* #nosec G304 */
if err != nil {
fmt.Println("failed to load config: " + err.Error())
os.Exit(-1)
}
conf := &gameserverConfig{}
err = json.Unmarshal(f, conf)
if err != nil {
fmt.Println("failed to unmarshal config file: " + err.Error())
os.Exit(-1)
}
return conf
}