Esempio n. 1
0
func DebugPid() {
	var db *dbm.DB = dbConnect(dbname)
	a, _ := db.Array("URLtoPageId")
	enum, err := a.Enumerator(true)
	//risky approach
	key2, value, err := enum.Next()
	for ; err != io.EOF; key2, value, err = enum.Next() {

		fmt.Printf("%v	%v\n", key2[0].(string), value[0].(int64))
	}
	db.Close()
}
Esempio n. 2
0
func GetPageId(URL string) int64 {
	var db *dbm.DB = dbConnect(dbname)
	URLtoPageId, _ := db.Array("URLtoPageId")
	pid, err := URLtoPageId.Get(URL)
	if err != nil {
		closeDb(db)
		return 0
	} else {
		closeDb(db)
		return pid.(int64)
	}

	return -1
}
Esempio n. 3
0
func SetPageId(URL string) int64 {
	var db *dbm.DB = dbConnect(dbname)
	URLtoPageId, _ := db.Array("URLtoPageId")
	pid, _ := URLtoPageId.Get(URL)
	if pid == nil {
		i := generatePId(URLtoPageId)
		//var i int64 = 0
		URLtoPageId.Set(i, URL)
		closeDb(db)
		return i
	} else {
		closeDb(db)
		return pid.(int64)
	}

	return -1
}
Esempio n. 4
0
func closeDb(db *dbm.DB) {
	err2 := db.Close()
	if err2 != nil {
		fmt.Printf("can't close")
	}
}