forked from evolutek/cellaserv2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.go
57 lines (49 loc) · 1.04 KB
/
settings.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
package main
import (
"os"
"gopkg.in/gcfg.v1"
"github.com/op/go-logging"
)
var cfg struct {
Cellaserv struct {
Debug string
Port string
}
Client struct {
Debug string
Host string
Port string
}
}
func setLogLevelFromString(lvl string) {
switch lvl {
case "":
case "0":
logLevel = logging.WARNING
case "1":
logLevel = logging.INFO
case "2":
logLevel = logging.DEBUG
default:
log.Warning("[Config] Unknown debug value: %s", lvl)
}
}
func setSockAddrListenFromString(addr string) {
if addr != "" && addr != ":" {
sockAddrListen = addr
}
}
func settingsSetup() {
err := gcfg.ReadFileInto(&cfg, "/etc/conf.d/cellaserv")
if err != nil {
// Not fatal, all values will be ""
log.Debug("[Config] %s", err)
}
// Override if not ""
setLogLevelFromString(cfg.Cellaserv.Debug)
setLogLevelFromString(os.Getenv("CS_DEBUG"))
setLogLevelFromString(*logLevelFlag)
setSockAddrListenFromString(":" + cfg.Cellaserv.Port)
setSockAddrListenFromString(":" + os.Getenv("CS_PORT"))
setSockAddrListenFromString(":" + *sockPortFlag)
}