-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
51 lines (43 loc) · 1.03 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
package main
import (
"fmt"
"io/ioutil"
"os"
"github.com/kelseyhightower/envconfig"
"gopkg.in/yaml.v2"
)
// Config represents a default config structure
type Config struct {
Database struct {
DbUser string `yaml:"dbuser" envconfig:"dbuser"`
Hostname string `yaml:"hostname" envconfig:"hostname"`
Password string `yaml:"password" envconfig:"password"`
Db string `yaml:"db" envconfig:"db"`
Port string `yaml:"port" envconfig:"port"`
} `yaml:"database"`
Telegram struct {
Botkey string `yaml:"botkey" envconfig:"botkey"`
ChatID int64 `yaml:"chatid" envconfig:"chatid"`
} `yaml:"telegram"`
}
func readConfigFile(config *Config) {
reader, _ := os.Open("config.yml")
yamlFile, err := ioutil.ReadAll(reader)
if err != nil {
fmt.Println(err)
os.Exit(2)
}
err = yaml.Unmarshal(yamlFile, &config)
if err != nil {
fmt.Println(err)
os.Exit(2)
}
}
func readConfigEnv(config *Config) {
err := envconfig.Process("", config)
if err != nil {
fmt.Println(err)
os.Exit(2)
}
fmt.Printf("%+v\n", config)
}