package main
import (
"fmt"
"io/ioutil"
"log"
"gopkg.in/yaml.v2"
)
type conf struct {
Enabled bool `yaml:"enabled"`
Port int32 `yaml:"port"`
ServerName string `yaml:"server_name"`
Timeout int64 `yaml:"timeout"`
}
func (c *conf) getConf() *conf {
yamlFile, err := ioutil.ReadFile("config/conf.yaml")
if err != nil {
log.Printf("yamlFile.Get err #%v ", err)
}
err = yaml.Unmarshal(yamlFile, c)
if err != nil {
log.Fatalf("Unmarshal: %v", err)
}
return c
}
func main() {
var configYaml conf
configYaml.getConf()
fmt.Println(configYaml,configYaml.Port)
}