65 lines
1.5 KiB
Go
65 lines
1.5 KiB
Go
|
package config
|
||
|
|
||
|
import (
|
||
|
"io/ioutil"
|
||
|
"log"
|
||
|
|
||
|
"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 {
|
||
|
var config Config
|
||
|
|
||
|
file, err := ioutil.ReadFile(path)
|
||
|
if err != nil {
|
||
|
log.Fatalf("Can't open config file: %v", err)
|
||
|
}
|
||
|
|
||
|
err = yaml.Unmarshal(file, &config)
|
||
|
if err != nil {
|
||
|
log.Fatalf("Error parsing config: %v", err)
|
||
|
}
|
||
|
|
||
|
return config
|
||
|
}
|