You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
telegabber/config/config.go

65 lines
1.5 KiB

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
}