12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- 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
- }
- type Step struct {
- Name string
- Subject string
- Steps []string
- Step string
- Remark string
- }
- type Db struct {
- Addr string
- Dbname string
- Remark string
- }
- 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
- }
|