conf.go 651 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package util
  2. import (
  3. "fmt"
  4. "io/ioutil"
  5. "gopkg.in/yaml.v2"
  6. )
  7. type Conf struct {
  8. Config Config
  9. }
  10. type Config struct {
  11. Natsurl string
  12. Threads int
  13. Process Step
  14. Mongodb Db
  15. }
  16. type Step struct {
  17. Name string
  18. Subject string
  19. Steps []string
  20. Step string
  21. Remark string
  22. }
  23. type Db struct {
  24. Addr string
  25. Dbname string
  26. Remark string
  27. }
  28. func GetConf() Conf {
  29. var conf Conf // 加载文件
  30. yamlFile, err := ioutil.ReadFile("conf.yaml")
  31. if err != nil {
  32. fmt.Println(err.Error())
  33. } // 将读取的yaml文件解析为响应的 struct
  34. err = yaml.Unmarshal(yamlFile, &conf)
  35. if err != nil {
  36. fmt.Println(err.Error())
  37. }
  38. return conf
  39. }