From 9b4a09677a352d9938e4505bfc2d0c8d304567ac Mon Sep 17 00:00:00 2001 From: bodqhrohro Date: Tue, 22 Oct 2019 19:36:54 +0300 Subject: Hello world XMPP echo component --- config/config.go | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 config/config.go (limited to 'config') diff --git a/config/config.go b/config/config.go new file mode 100644 index 0000000..be05cb5 --- /dev/null +++ b/config/config.go @@ -0,0 +1,64 @@ +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 +} -- cgit v1.2.3