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
2017-10-11 06:53:50 +04:00

51 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// i2_bot Instinct PokememBro Bot
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
package config
import (
// stdlib
"io/ioutil"
"log"
"path/filepath"
// 3rd-party
"gopkg.in/yaml.v2"
)
const VERSION = "0.25"
type DatabaseConnection struct {
Host string `yaml:"host"`
Port string `yaml:"port"`
User string `yaml:"user"`
Password string `yaml:"password"`
Database string `yaml:"database"`
}
type TelegramConnection struct {
APIToken string `yaml:"api_token"`
}
type Config struct {
Telegram TelegramConnection `yaml:"telegram_connection"`
Database DatabaseConnection `yaml:"database_connection"`
}
func (c *Config) Init() {
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")
}
}
func New() *Config {
c := &Config{}
return c
}