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

66 lines
1.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// i2_bot Instinct PokememBro Bot
// Copyright (c) 2017 Vladimir "fat0troll" Hodakov
package config
import (
"gopkg.in/yaml.v2"
"io/ioutil"
"log"
"path/filepath"
)
const VERSION = "0.35"
// DatabaseConnection handles database connection settings in config.yaml
type DatabaseConnection struct {
Host string `yaml:"host"`
Port string `yaml:"port"`
User string `yaml:"user"`
Password string `yaml:"password"`
Database string `yaml:"database"`
}
// TelegramConnection handles settings for Telegram connection in config.yaml
type TelegramConnection struct {
APIToken string `yaml:"api_token"`
}
// NotificationsConnection handles settings for notifications
type NotificationsConnection struct {
GroupID string `yaml:"group_id"`
}
// LoggingConfig handles log file configuration
type LoggingConfig struct {
LogPath string `yaml:"log_path"`
}
// Config is a struct which represents config.yaml structure
type Config struct {
Telegram TelegramConnection `yaml:"telegram_connection"`
Database DatabaseConnection `yaml:"database_connection"`
Notifications NotificationsConnection `yaml:"notifications"`
Logs LoggingConfig `yaml:"logs"`
}
// Init is a configuration initializer
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")
}
}
// New creates new empty Config object
func New() *Config {
c := &Config{}
return c
}