-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
49 lines (37 loc) · 980 Bytes
/
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
package main
import (
"fmt"
"gopkg.in/fzerorubigd/onion.v3"
_ "gopkg.in/fzerorubigd/onion.v3/tomlloader"
)
type Config struct {
serverAddress string
teamName string
}
const (
DEFAULT_SERVER_HOST string = "127.0.0.1"
DEFAULT_SERVER_PORT int = 6000
DEFAULT_TEAM_NAME string = "Janstun"
)
const (
ConfServerHost string = "server.host"
ConfServerPort string = "server.port"
ConfTeamName string = "team.name"
)
func LoadConfigs(o *onion.Onion) Config {
cfg := Config{
teamName: o.GetString(ConfTeamName),
serverAddress: fmt.Sprintf("%s:%d", o.GetString(ConfServerHost), o.GetInt(ConfServerPort)),
}
return cfg
}
func defaultConfig(name, filename string) *onion.Onion {
o := onion.New()
dl := onion.NewDefaultLayer()
dl.SetDefault(ConfServerHost, DEFAULT_SERVER_HOST)
dl.SetDefault(ConfServerPort, DEFAULT_SERVER_PORT)
dl.SetDefault(ConfTeamName, DEFAULT_TEAM_NAME)
o.AddLayer(dl)
o.AddLayer(onion.NewFileLayer(filename))
return o
}