This repository has been archived by the owner on Mar 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
72 lines (59 loc) · 1.63 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
package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"github.com/go-yaml/yaml"
)
// Conf - структура конфига
type Conf struct {
Title string `yaml:"title"`
Server struct {
HTTP struct {
Port string `yaml:"port"`
} `yaml:"http"`
DNS struct {
Port string `yaml:"port"`
Network string `yaml:"network"`
TTL uint32 `yaml:"ttl"`
} `yaml:"dns"`
} `yaml:"server"`
Log struct {
Network string `yaml:"network"`
Host string `yaml:"host"`
Port string `yaml:"port"`
Type string `yaml:"type"`
Debug bool `yaml:"debug mode"`
Severity string `yaml:"severity"`
Facility string `yaml:"facility"`
FilePath string `yaml:"file path"`
FileName string `yaml:"file name"`
} `yaml:"log"`
Storage struct {
Login string `yaml:"login"`
Password string `yaml:"password"`
Bucket string `yaml:"bucket"`
Hosts []string `yaml:"hosts"`
} `yaml:"storage"`
Metrics struct {
Port string `yaml:"port"`
} `yaml:"metrics"`
}
// "-c" - флаг для указания конфиг файла (по умолчанию будет использоваться config.yaml)
var configFlag = flag.String("c", "./config.yaml", "set config file in the yaml format")
// Config - объявляем переменную для работы с данными конфига
var Config Conf
func configure() Conf {
configFile, err := ioutil.ReadFile(*configFlag)
if err != nil {
fmt.Println("Failed read configuration file: ", err)
os.Exit(1)
}
var c Conf
err = yaml.Unmarshal(configFile, &c)
if err != nil {
fmt.Println("Failed unmarshal ", *configFlag, err)
}
return c
}