package util import ( "fmt" "io/ioutil" "gopkg.in/yaml.v2" ) type Conf struct { Config Config } type Config struct { Natsurl string Threads int Process Step Mongodb Db MongodbQ Db MongodbP Db Redis Redis Es Es KeywordAddr string Fields []string } type Step struct { Name string Subject string Steps []string Step string Remark string } type Db struct { Addr string Dbname string Coll string Dbsize int Username string Password string } type Redis struct { Addr string DbIndex int } type Es struct { Addr string User string Password string Size int } func GetConf() Conf { var conf Conf // 加载文件 yamlFile, err := ioutil.ReadFile("conf.yaml") if err != nil { fmt.Println(err.Error()) } // 将读取的yaml文件解析为响应的 struct err = yaml.Unmarshal(yamlFile, &conf) if err != nil { fmt.Println(err.Error()) } return conf }