blob: 2ec670601f81abf851ccb7ba00ef55d308d0ec59 (
plain) (
blame)
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
|
package config
import (
"github.com/pkg/errors"
"io/ioutil"
"gopkg.in/yaml.v2"
)
type Config struct {
Telegram TelegramConfig `yaml:":telegram"`
Xmpp XmppConfig `yaml:":xmpp"`
}
type XmppConfig struct {
Loglevel string `yaml:":loglevel"`
Jid string `yaml:":jid"`
Host string `yaml:":host"`
Port string `yaml:":port"`
Password string `yaml:":password"`
Db string `yaml:":db"`
}
type TelegramConfig struct {
Loglevel string `yaml:":loglevel"`
Content TelegramContentConfig `yaml:":content"`
Verbosity uint8 `yaml:":tdlib_verbosity"`
Tdlib TelegramTdlibConfig `yaml:":tdlib"`
}
type TelegramContentConfig struct {
Path string `yaml:":path"`
Link string `yaml:":link"`
Upload string `yaml:":upload"`
}
type TelegramTdlibConfig struct {
Path string `yaml:":lib_path"`
Client TelegramTdlibClientConfig `yaml:":client"`
}
type TelegramTdlibClientConfig struct {
ApiId string `yaml:":api_id"`
ApiHash string `yaml:":api_hash"`
DeviceModel string `yaml:":device_model"`
ApplicationVersion string `yaml:":application_version"`
UseChatInfoDatabase bool `yaml:":use_chat_info_database"`
}
func ReadConfig(path string) (Config, error) {
var config Config
file, err := ioutil.ReadFile(path)
if err != nil {
return config, errors.Wrap(err, "Can't open config file")
}
err = yaml.Unmarshal(file, &config)
if err != nil {
return config, errors.Wrap(err, "Error parsing config")
}
return config, nil
}
|