conf.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // main
  2. package main
  3. import (
  4. "encoding/json"
  5. "fmt"
  6. "io/ioutil"
  7. "log"
  8. "os"
  9. mgo "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
  10. )
  11. var (
  12. db *mgo.MongodbSim
  13. cf Config
  14. ucf UserConfig
  15. )
  16. type Config struct {
  17. Database struct {
  18. Host string `json:"host"`
  19. DBName string `json:"dbname"`
  20. DBSize int `json:"dbsize"`
  21. } `json:"database"`
  22. Wanpan struct {
  23. Webdav string `json:"webdav"`
  24. User string `json:"user"`
  25. Sercert string `json:"sercert"`
  26. } `json:"wangpan"`
  27. YusuanInfo string `json:"yusuaninfo"`
  28. ProjectItem string `json:"projectitem"`
  29. Projectitem_field []string `json:"projectitem_field"`
  30. Collections string `json:"collections"`
  31. Projectitem_field_mingxi []string `json:"projectitem_field_mingxi"`
  32. Yusuan_mingxi string `json:"yusuan_mingxi"`
  33. }
  34. type UserConfig struct {
  35. Totbale string `json:"totbale"`
  36. User string `json:"user"`
  37. Rules []Rule `json:"rules"`
  38. }
  39. type Rule struct {
  40. Index string `json:"index"`
  41. Match string `json:"match"`
  42. MatchField MatchField `json:"match_field"`
  43. MatchAdd string `json:"match_add"`
  44. MatchAddField MatchField `json:"match_add_field"`
  45. NotMatch string `json:"not_match"`
  46. NotMatchField MatchField `json:"not_match_field"`
  47. }
  48. type MatchField struct {
  49. Field []string `json:"field"`
  50. Remark string `json:"remark"`
  51. }
  52. func init() {
  53. data, err := ioutil.ReadFile("conf.json")
  54. if err != nil {
  55. fmt.Println("Failed to read config file:", err)
  56. os.Exit(1)
  57. }
  58. err = json.Unmarshal(data, &cf)
  59. if err != nil {
  60. fmt.Println("Failed to parse config file:", err)
  61. os.Exit(1)
  62. }
  63. log.Println("加载完成", cf)
  64. db = &mgo.MongodbSim{
  65. MongodbAddr: cf.Database.Host,
  66. DbName: cf.Database.DBName,
  67. Size: cf.Database.DBSize,
  68. //UserName: "root", //root
  69. //Password: "top@123", //top@123
  70. //ReplSet: "",
  71. //Direct: true,
  72. }
  73. db.InitPool()
  74. log.Println("初始化mgo完成")
  75. }