package lib

import (
	"fmt"
	"io/ioutil"
	"gopkg.in/yaml.v2"
)

type AutoGenerated struct {
	Config Config `yaml:"config"`
}

type Config struct {
	Server Server `yaml:"server"`
	Db     Db     `yaml:"db"`
}

type Server struct {
	Host string `yaml:"host"`
	Port int    `yaml:"port"`
}

type Db struct {
	Pass string `yaml:"pass"`
	Name string `yaml:"name"`
	User string `yaml:"user"`
	Host string `yaml:"host"`
	Port string `yaml:"port"`
}



func GetConf() *Config{
	var conf AutoGenerated // 加载文件
	yamlFile, err := ioutil.ReadFile("./conf/conf.yaml")
	if err != nil {
		fmt.Println(err.Error())
	} // 将读取的yaml文件解析为响应的 struct
	err = yaml.Unmarshal(yamlFile, &conf)
	if err != nil {
		fmt.Println(err.Error())
	}
	// fmt.Println(conf.Config.Server.Host)
	return &conf.Config
}