func NewTaobaoESStore(c Config) *TaobaoESStore { var esstor = &TaobaoESStore{} var err error var m = mongodb.MongodbConf{} esstor.client, err = elastic.NewClient(elastic.SetURL(strings.Split(c.ESHost, ",")...)) if err != nil { log.Fatal(err) } m.Db = "xu_precise" m.Host = c.MgoStoreHost m.Port = c.MgoStorePort m.UName = c.mgoStoreUname m.Upwd = c.mgoStoreUpwd esstor.store, err = mongodb.NewMongodb(m) if err != nil { log.Fatal(err) } esstor.prefix = c.TablePrefixe esstor.initCategory() esstor.geohost = c.GeoHost esstor.bulk = esstor.client.Bulk() return esstor }
// 获取mongo对象 func GetMongoObj() (*mongodb.Mongodb, error) { murls := strings.Split(GetConfVal("zhejiang::mongo_url"), ":") conf := mongodb.MongodbConf{} conf.Host = murls[0] conf.Port = murls[1] conf.Db = "data_source" return mongodb.NewMongodb(conf) }
// 获取mongodb对象 func GetMongoObj(iniPath string, section string) (*mongodb.Mongodb, error) { confObj, err := GetConfObj(iniPath) if err != nil { return nil, errors.Trace(err) } conf := mongodb.MongodbConf{} conf.Host = confObj.String(section + "::" + "host") conf.Db = confObj.String(section + "::" + "db") conf.Port = confObj.String(section + "::" + "port") conf.UName = confObj.String(section + "::" + "user") conf.Upwd = confObj.String(section + "::" + "pwd") return mongodb.NewMongodb(conf) }
func init() { var cf mongodb.MongodbConf var err error cf.Db = fp.mongoDb cf.Host = fp.mongoHost cf.Port = fp.mongoPort cf.UName = fp.mongoUname cf.Upwd = fp.mongoUpwd db, err = mongodb.NewMongodb(cf) if err != nil { log.Fatal(err) } }