conf.go 966 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. MongodbQ Db
  16. MongodbP Db
  17. Redis Redis
  18. Es Es
  19. KeywordAddr string
  20. Fields []string
  21. }
  22. type Step struct {
  23. Name string
  24. Subject string
  25. Steps []string
  26. Step string
  27. Remark string
  28. }
  29. type Db struct {
  30. Addr string
  31. Dbname string
  32. Coll string
  33. Dbsize int
  34. Username string
  35. Password string
  36. }
  37. type Redis struct {
  38. Addr string
  39. DbIndex int
  40. }
  41. type Es struct {
  42. Addr string
  43. User string
  44. Password string
  45. Size int
  46. }
  47. func GetConf() Conf {
  48. var conf Conf // 加载文件
  49. yamlFile, err := ioutil.ReadFile("conf.yaml")
  50. if err != nil {
  51. fmt.Println(err.Error())
  52. } // 将读取的yaml文件解析为响应的 struct
  53. err = yaml.Unmarshal(yamlFile, &conf)
  54. if err != nil {
  55. fmt.Println(err.Error())
  56. }
  57. return conf
  58. }