Archived
1
This repository has been archived on 2022-11-04. You can view files and clone it, but cannot push or open issues or pull requests.
i2_bot/lib/config/config.go

51 lines
956 B
Go
Raw Normal View History

2017-10-04 17:56:18 +04:00
// i2_bot Instinct PokememBro Bot
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
package config
import (
2017-10-18 07:03:34 +04:00
// stdlib
"io/ioutil"
"log"
"path/filepath"
// 3rd-party
"gopkg.in/yaml.v2"
2017-10-04 17:56:18 +04:00
)
2017-10-13 03:52:04 +04:00
const VERSION = "0.29"
2017-10-04 17:56:18 +04:00
type DatabaseConnection struct {
2017-10-18 07:03:34 +04:00
Host string `yaml:"host"`
Port string `yaml:"port"`
User string `yaml:"user"`
Password string `yaml:"password"`
Database string `yaml:"database"`
2017-10-04 17:56:18 +04:00
}
type TelegramConnection struct {
2017-10-18 07:03:34 +04:00
APIToken string `yaml:"api_token"`
2017-10-04 17:56:18 +04:00
}
type Config struct {
2017-10-18 07:03:34 +04:00
Telegram TelegramConnection `yaml:"telegram_connection"`
Database DatabaseConnection `yaml:"database_connection"`
2017-10-04 17:56:18 +04:00
}
func (c *Config) Init() {
2017-10-18 07:03:34 +04:00
fname, _ := filepath.Abs("./config.yml")
yamlFile, yerr := ioutil.ReadFile(fname)
if yerr != nil {
log.Fatal("Can't read config file")
}
yperr := yaml.Unmarshal(yamlFile, c)
if yperr != nil {
log.Fatal("Can't parse config file")
}
2017-10-04 17:56:18 +04:00
}
func New() *Config {
2017-10-18 07:03:34 +04:00
c := &Config{}
return c
2017-10-04 17:56:18 +04:00
}