当前位置: 首页>>代码示例>>Golang>>正文


Golang mgo.Session类代码示例

本文整理汇总了Golang中launchpad/net/mgo.Session的典型用法代码示例。如果您正苦于以下问题:Golang Session类的具体用法?Golang Session怎么用?Golang Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Session类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: DropDatabase

func DropDatabase(dbConn *mgo.Session, dbName string) error {
	var err = dbConn.DB(dbName).DropDatabase()
	if Panic && (err != nil) {
		panic(err)
	}
	return err
}
开发者ID:hyl87,项目名称:2011_Go_Geo_Gfx,代码行数:7,代码来源:dbutil.go

示例2: Crawl

func Crawl(pool *mgo.Session, du *DigestwUser, tl *TwTimeLine, resolveURL bool, done chan<- int) {
	defer func() { done <- 0 }()
	sess := pool.New()
	defer sess.Close()
	sa := NewStatsAll(du.TwUser.Screen_Name, sess)
	var sid, first, last int64
	for k, v := range *tl {
		tmpTime, _ := time.Parse(time.RubyDate, v.Created_at)
		tmpSec := tmpTime.Seconds()
		if du.UTC_Offset != nil {
			tmpSec += *du.UTC_Offset
			v.Created_at = time.SecondsToUTC(tmpSec).Format(time.RubyDate)
		}
		if k == 0 {
			sid = v.Id
			last = tmpSec
		}
		addStats(sa, &v, resolveURL)
		if k == (len(*tl) - 1) {
			first = tmpSec
		}
		//log.Printf("id:%d", v.Id)
	}
	sa.Foreach(update)
	// decide to the next execution time
	du.SinceId = strconv.Itoa64(sid)
	du.NextSeconds = time.Seconds() + (last - first)
	if _, err := du.Upsert(sess); err != nil {
		log.Print(err)
	}
}
开发者ID:mocchira,项目名称:digestw,代码行数:31,代码来源:twitter2mongo.go

示例3: EnsureIndex

func EnsureIndex(dbConn *mgo.Session, dbName string, collName string, index *mgo.Index) error {
	var err = dbConn.DB(dbName).C(collName).EnsureIndex(*index)
	if Panic && (err != nil) {
		panic(err)
	}
	return err
}
开发者ID:hyl87,项目名称:2011_Go_Geo_Gfx,代码行数:7,代码来源:dbutil.go

示例4: Insert

func Insert(dbConn *mgo.Session, dbName string, collName string, recs ...interface{}) error {
	var err = dbConn.DB(dbName).C(collName).Insert(recs...)
	if Panic && (err != nil) {
		panic(err)
	}
	return err
}
开发者ID:hyl87,项目名称:2011_Go_Geo_Gfx,代码行数:7,代码来源:dbutil.go

示例5: Find

func (su *StatsUnit) Find(sess *mgo.Session, col, uid, unitid string) os.Error {
	c := sess.DB(MGO_DB).C(col)
	if unitid == "" {
		return c.Find(bson.M{"userid": uid}).One(su)
	}
	return c.Find(bson.M{"userid": uid, "unitid": unitid}).One(su)
}
开发者ID:mocchira,项目名称:digestw,代码行数:7,代码来源:model.go

示例6: 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)
			}
		}
	}
}
开发者ID:hyl87,项目名称:2011_Go_Geo_Gfx,代码行数:52,代码来源:geodata.go

示例7: GeoNamesDbName

func GeoNamesDbName(dbConn *mgo.Session, force bool) string {
	if force || (len(geoNamesDbName) == 0) {
		var last = ""
		dbNames, err := dbConn.DatabaseNames()
		if err != nil {
			panic(err)
		}
		for _, dbn := range dbNames {
			if strings.HasPrefix(dbn, "gn_") {
				last = dbn
			}
		}
		geoNamesDbName = last
	}
	return geoNamesDbName
}
开发者ID:hyl87,项目名称:2011_Go_Geo_Gfx,代码行数:16,代码来源:dbutil.go

示例8: getPage

func getPage(session *mgo.Session, title string) (result *Page, err error) {
	result = new(Page)
	c := session.DB(dbname).C("pages")
	err = c.Find(bson.M{"title": title}).One(result)
	return
}
开发者ID:georgerogers42,项目名称:gwiki,代码行数:6,代码来源:gwiki.go

示例9: createDb

func createDb(sourceDir string) {
	var err error
	var dbConn *mgo.Session
	var dbIndex, lastIndex = 0, 0
	var dbName, tmp string
	var dbNames []string
	var admins []*adminDiv
	var features = []string{}
	var timezones = []string{}
	var countries = []string{}
	fmt.Println("Connecting...")
	dbutil.Panic = true
	dbConn, err = dbutil.ConnectToGlobal()
	dbNames, err = dbConn.DatabaseNames()
	if err != nil {
		panic(err)
	}
	for _, dbName = range dbNames {
		if strings.HasPrefix(dbName, "gn_") {
			dbIndex++
		}
	}
	for {
		dbName = fmt.Sprintf("gn_%d", dbIndex)
		if stringutil.InSliceAt(dbNames, dbName) < 0 {
			break
		} else {
			dbIndex++
		}
	}
	createDbCollection(dbConn, dbName, path.Join(sourceDir, "timeZones.txt"), "t", true, false, func(index int, rec []string) bson.M {
		var n = strings.Replace(rec[0], "_", " ", -1)
		timezones = append(timezones, n)
		return bson.M{"_id": index - 1, "n": n, "g": stringutil.ToFloat32(rec[1]), "d": stringutil.ToFloat32(rec[2]), "r": stringutil.ToFloat32(rec[3])}
	})
	createDbCollection(dbConn, dbName, path.Join(sourceDir, "featureCodes_en.txt"), "f", false, false, func(index int, rec []string) bson.M {
		features = append(features, rec[0])
		return bson.M{"_id": index, "n": rec[0], "t": rec[1], "d": rec[2]}
	})
	createDbCollection(dbConn, dbName, path.Join(sourceDir, "countryInfo.txt"), "c", false, false, func(index int, rec []string) bson.M {
		/*
			#ISO	ISO3	ISO-Numeric	fips	Country					Capital				Area(in sq km)	Population	Continent	tld	CurrencyCode	CurrencyName	Phone	Postal Code Format	Postal Code Regex	Languages			geonameid	neighbours	EquivalentFipsCode
			AD		AND		020			AN		Andorra					Andorra la Vella	468				84000		EU			.ad	EUR				Euro			376		AD###				^(?:AD)*(\d{3})$	ca					3041565		ES,FR
			AE		ARE		784			AE		United Arab Emirates	Abu Dhabi			82880			4975593		AS			.ae	AED				Dirham			971												ar-AE,fa,en,hi,ur	290557		SA,OM
		*/
		countries = append(countries, rec[0])
		return bson.M{"_id": index, "i": rec[0], "i3": rec[1], "f": rec[2], "t": rec[4], "ca": rec[5], "co": rec[8], "d": rec[9], "cc": rec[10], "cn": rec[11], "p": rec[12], "l": stringutil.Split(rec[15], ","), "g": stringutil.ToInt(rec[16]), "n": stringutil.Split(rec[17], ",")}
	})
	createDbCollection(dbConn, dbName, path.Join(sourceDir, "zip_allCountries.txt"), "z", false, true, func(index int, rec []string) bson.M {
		var an = []string{stringutil.Title(rec[3]), stringutil.Title(rec[5]), stringutil.Title(rec[7])}
		var ac = []string{rec[4], rec[6], rec[8]}
		var ll, err = numutil.NewDvec2(rec[10], rec[9])
		var n = rec[2]
		var r = bson.M{"_id": index, "c": stringutil.InSliceAt(countries, rec[0]), "z": rec[1], "n": n}
		var words []string
		if (err == nil) && (ll.X >= geoutil.LonMin) && (ll.X <= geoutil.LonMax) && (ll.Y >= geoutil.LatMin) && (ll.Y <= geoutil.LatMax) {
			r["l"] = ll
		} else {
			return nil
		}
		r["a"], admins = findAdminIndex(admins, rec[0], ac[0], ac[1], ac[2], an)
		if len(n) > 0 {
			if n == strings.ToUpper(n) {
				n = stringutil.Title(n)
			}
			if words = stringutil.Split(n, " "); len(words) > 1 {
				n = ""
				for i, w := range words {
					if stringutil.InSliceAt(words, w) == i {
						n = stringutil.Concat(n, w, " ")
					}
				}
				r["n"] = n[0 : len(n)-1]
			} else {
				r["n"] = n
			}
		}
		return r
	})
	for i, ad := range admins {
		dbutil.Insert(dbConn, dbName, "a", fixupAdminDiv(bson.M{"_id": i, "a": stringutil.NonEmpties(true, ad.ac1, ad.ac2, ad.ac3, ad.ac4), "n": ad.n}, countries))
	}
	stringutil.ForEach(func(i int, s string) {
		createDbCollection(dbConn, dbName, path.Join(sourceDir, s), "a", false, false, func(index int, rec []string) bson.M {
			var a = stringutil.Split(rec[0], ".")
			var n, na = rec[1], rec[2]
			var r bson.M
			for _, ad := range admins {
				if (ad.ac1 == a[0]) && (ad.ac2 == a[1]) && ((len(a) == 2) || (ad.ac3 == a[2])) {
					return nil
				}
			}
			index += len(admins)
			if i == 0 {
				lastIndex = index
			} else {
				index = index + 1 + lastIndex
			}
			r = bson.M{"_id": index, "a": a, "g": stringutil.ToInt(rec[3]), "n": n, "na": na}
			return fixupAdminDiv(r, countries)
//.........这里部分代码省略.........
开发者ID:hyl87,项目名称:2011_Go_Geo_Gfx,代码行数:101,代码来源:geodata.go

示例10: Find

func Find(dbConn *mgo.Session, dbName string, collName string, query interface{}) *mgo.Query {
	return dbConn.DB(dbName).C(collName).Find(query)
}
开发者ID:hyl87,项目名称:2011_Go_Geo_Gfx,代码行数:3,代码来源:dbutil.go

示例11: FindOne

func (su *DigestwUser) FindOne(sess *mgo.Session, sn string) os.Error {
	c := sess.DB(MGO_DB).C(MGO_COL_USER)
	return c.Find(bson.M{"screen_name": sn}).One(su)
}
开发者ID:mocchira,项目名称:digestw,代码行数:4,代码来源:model.go

示例12: Upsert

func (su *DigestwUser) Upsert(sess *mgo.Session) (interface{}, os.Error) {
	c := sess.DB(MGO_DB).C(MGO_COL_USER)
	return c.Upsert(bson.M{"screen_name": su.TwUser.Screen_Name}, su)
}
开发者ID:mocchira,项目名称:digestw,代码行数:4,代码来源:model.go


注:本文中的launchpad/net/mgo.Session类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。