-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
45 lines (36 loc) · 820 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
package main
import (
"io/ioutil"
"log"
"gopkg.in/yaml.v3"
)
type TelegramConfig struct {
Token string `yaml:"token"`
Username string `yaml:"username"`
}
type AccountConfig struct {
Address string `yaml:"address"`
Alias string `yaml:"alias"`
}
type Config struct {
EthUrl string `yaml:"eth-url"`
Accounts []AccountConfig `yaml:"accounts"`
Telegram *TelegramConfig `yaml:"telegram"`
}
func LoadConfig(configPath string) (config *Config, err error) {
configData, err := ioutil.ReadFile(configPath)
if err != nil {
return nil, err
}
config = &Config{}
if err = yaml.Unmarshal(configData, config); err != nil {
return
}
if len(config.Accounts) == 0 {
log.Fatalf("Config is missing accounts")
}
if config.EthUrl == "" {
log.Fatalf("Config is missing eth-url")
}
return
}