本文整理汇总了Golang中launchpad/net/mgo.Session.Close方法的典型用法代码示例。如果您正苦于以下问题:Golang Session.Close方法的具体用法?Golang Session.Close怎么用?Golang Session.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类launchpad/net/mgo.Session
的用法示例。
在下文中一共展示了Session.Close方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: createGobs
func createGobs(targetDir string) {
var makeGob = func(bmap interface{}, ptr interface{}) interface{} {
dbutil.BsonMapToObject(bmap, ptr)
return ptr
}
var makeAdminGob = func(bmap interface{}) interface{} {
return makeGob(bmap, &geoutil.GeoNamesAdminRecord{})
}
var makeNameGob = func(bmap interface{}) interface{} {
return makeGob(bmap, &geoutil.GeoNamesNameRecord{})
}
var makeZipGob = func(bmap interface{}) interface{} {
return makeGob(bmap, &geoutil.GeoNamesZipRecord{})
}
var lola numutil.Dvec2
var box [2][2]float64
var dbConn *mgo.Session
var dbName, fbName, fp string
var geoRecs []interface{}
dbutil.Panic = true
dbConn, _ = dbutil.ConnectToGlobal()
defer dbConn.Close()
dbName = dbutil.GeoNamesDbName(dbConn, true)
dbutil.FindAll(dbConn, dbName, "a", nil, &geoRecs)
gobutil.CreateGobsFile(path.Join(targetDir, "ga"), &geoRecs, makeAdminGob, true)
for lola.Y = geoutil.LatMin; lola.Y < geoutil.LatMax; lola.Y++ {
for lola.X = geoutil.LonMin; lola.X < geoutil.LonMax; lola.X++ {
fbName = geoutil.LoLaFileName(lola.X, lola.Y)
fmt.Println(fbName)
geoRecs = nil
box[0][0] = lola.X
box[0][1] = lola.Y
box[1][0] = lola.X + 1
box[1][1] = lola.Y + 1
dbutil.FindAll(dbConn, dbName, "n", bson.M{"l": bson.M{"$within": bson.M{"$box": box}}}, &geoRecs)
if len(geoRecs) == 0 {
geoRecs = nil
dbutil.FindOne(dbConn, dbName, "n", bson.M{"l": bson.M{"$near": []float64{lola.X + 0.5, lola.Y + 0.5}}}, &geoRecs)
}
fp = path.Join(path.Join(targetDir, "gn"), fbName)
fmt.Println(fp)
gobutil.CreateGobsFile(fp, &geoRecs, makeNameGob, true)
geoRecs = nil
dbutil.FindAll(dbConn, dbName, "z", bson.M{"l": bson.M{"$within": bson.M{"$box": box}}}, &geoRecs)
if len(geoRecs) > 0 {
fp = path.Join(path.Join(targetDir, "gz"), fbName)
fmt.Println(fp)
gobutil.CreateGobsFile(fp, &geoRecs, makeZipGob, true)
}
}
}
}