/
config.go
58 lines (48 loc) · 1004 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
50
51
52
53
54
55
56
57
58
package main
/*
Описание конфигурационного файла
*/
import (
"fmt"
"time"
"github.com/BurntSushi/toml"
"github.com/labstack/gommon/log"
)
type settings struct {
Host string
Port string
ConLiveSec int `toml:"con_live_sec"`
LogLevel string `toml:"log_level"`
}
func (c *settings) Load(confPath string) error {
if _, err := toml.DecodeFile(confPath, c); err != nil {
return fmt.Errorf("Ошибка разбора файла настроек: %v", err)
}
return nil
}
func (c *settings) getListenAddress() string {
return c.Host + ":" + c.Port
}
func (c *settings) getLogLevel() log.Lvl {
var lvl log.Lvl
switch c.LogLevel {
case "DEBUG":
lvl = log.DEBUG
break
case "INFO":
lvl = log.INFO
break
case "WARN":
lvl = log.WARN
break
case "ERROR":
lvl = log.ERROR
break
default:
lvl = log.INFO
}
return lvl
}
func (c *settings) getEmptyConnTTL() time.Duration {
return time.Duration(c.ConLiveSec) * time.Second
}