-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
41 lines (32 loc) · 889 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
package main
import (
"log"
"github.com/knadh/koanf"
"github.com/knadh/koanf/parsers/toml"
"github.com/knadh/koanf/providers/file"
)
// cfgTelegram contains config regarding telegram
type cfgTelegram struct {
APIKey string `koanf:"api_key"`
}
// cfgSplitwise contains config regarding Splitwise
type cfgSplitwise struct {
ConsumerKey string `koanf:"consumer_key"`
ConsumerSecret string `koanf:"consumer_secret"`
Token string `koanf:"token"`
TokenSecret string `koanf:"token_secret"`
}
// Config represents app config
type Config struct {
Telegram cfgTelegram
Splitwise cfgSplitwise
}
var cfg Config
func initConfig() {
var k = koanf.New(".")
if err := k.Load(file.Provider("config.toml"), toml.Parser()); err != nil {
log.Fatalf("couldn't read config: %v", err)
}
k.Unmarshal("telegram", &cfg.Telegram)
k.Unmarshal("splitwise", &cfg.Splitwise)
}