conf.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. }
  31. type UserConfig struct {
  32. Totbale string `json:"totbale"`
  33. User string `json:"user"`
  34. Rules []Rule `json:"rules"`
  35. }
  36. type Rule struct {
  37. Index string `json:"index"`
  38. Match string `json:"match"`
  39. MatchField MatchField `json:"match_field"`
  40. MatchAdd string `json:"match_add"`
  41. MatchAddField MatchField `json:"match_add_field"`
  42. NotMatch string `json:"not_match"`
  43. NotMatchField MatchField `json:"not_match_field"`
  44. }
  45. type MatchField struct {
  46. Field []string `json:"field"`
  47. Remark string `json:"remark"`
  48. }
  49. func init() {
  50. data, err := ioutil.ReadFile("conf.json")
  51. if err != nil {
  52. fmt.Println("Failed to read config file:", err)
  53. os.Exit(1)
  54. }
  55. err = json.Unmarshal(data, &cf)
  56. if err != nil {
  57. fmt.Println("Failed to parse config file:", err)
  58. os.Exit(1)
  59. }
  60. log.Println("加载完成", cf)
  61. db = &mgo.MongodbSim{
  62. MongodbAddr: cf.Database.Host,
  63. DbName: cf.Database.DBName,
  64. Size: cf.Database.DBSize,
  65. //UserName: "root", //root
  66. //Password: "top@123", //top@123
  67. //ReplSet: "",
  68. //Direct: true,
  69. }
  70. db.InitPool()
  71. log.Println("初始化mgo完成")
  72. }