aboutsummaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
authorbodqhrohro <bodqhrohro@gmail.com>2019-10-22 19:36:54 +0300
committerbodqhrohro <bodqhrohro@gmail.com>2019-10-22 19:36:54 +0300
commit9b4a09677a352d9938e4505bfc2d0c8d304567ac (patch)
tree1863f0d4c58f4019f86910f76c96f5823fd01dd4 /config
Hello world XMPP echo component
Diffstat (limited to 'config')
-rw-r--r--config/config.go64
1 files changed, 64 insertions, 0 deletions
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
+}