// main package main import ( "encoding/json" "fmt" "io/ioutil" "log" "os" mgo "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb" ) var ( db *mgo.MongodbSim cf Config ucf UserConfig ) type Config struct { Database struct { Host string `json:"host"` DBName string `json:"dbname"` DBSize int `json:"dbsize"` } `json:"database"` Wanpan struct { Webdav string `json:"webdav"` User string `json:"user"` Sercert string `json:"sercert"` } `json:"wangpan"` YusuanInfo string `json:"yusuaninfo"` ProjectItem string `json:"projectitem"` Projectitem_field []string `json:"projectitem_field"` } type UserConfig struct { Totbale string `json:"totbale"` User string `json:"user"` Rules []Rule `json:"rules"` } type Rule struct { Index string `json:"index"` Match string `json:"match"` MatchField MatchField `json:"match_field"` MatchAdd string `json:"match_add"` MatchAddField MatchField `json:"match_add_field"` NotMatch string `json:"not_match"` NotMatchField MatchField `json:"not_match_field"` } type MatchField struct { Field []string `json:"field"` Remark string `json:"remark"` } func init() { data, err := ioutil.ReadFile("conf.json") if err != nil { fmt.Println("Failed to read config file:", err) os.Exit(1) } err = json.Unmarshal(data, &cf) if err != nil { fmt.Println("Failed to parse config file:", err) os.Exit(1) } log.Println("加载完成", cf) db = &mgo.MongodbSim{ MongodbAddr: cf.Database.Host, DbName: cf.Database.DBName, Size: cf.Database.DBSize, //UserName: "root", //root //Password: "top@123", //top@123 //ReplSet: "", //Direct: true, } db.InitPool() log.Println("初始化mgo完成") }