package common

import (
	"github.com/pkg/errors"
	"gopkg.in/yaml.v3"
	"io/ioutil"
)

type conf struct {
	Host     string `yaml:"host"`
	Port     string `yaml:"port"`
	Password string `yaml:"password"`
	Db       int    `yaml:"db"`
}

func GetConfig() (dbConf conf, err error) {
	yamlFile, err := ioutil.ReadFile("./config/config.yml")
	if err != nil {
		return dbConf, errors.Wrap(err,"ERR: fail to get config")
	}
	err = yaml.Unmarshal(yamlFile, &dbConf)
	if err != nil {
		return dbConf, errors.Wrap(err,"ERR: fail to get config")
	}
	return
}