Exemple #1
0
func saveItem(db *leveldb.DB, it *gohn.Item) {
	pbmsg, err := proto.Marshal(it)
	check(err)
	key := []byte(strconv.Itoa(int(it.GetId())))
	err = db.Put(key, pbmsg, nil)
	check(err)
}
Exemple #2
0
func logItem(it *gohn.Item) {
	log.Printf("Item %d\n", it.GetId())
	if it.Title != nil {
		log.Printf("Title: %s\n", it.GetTitle())
	}
	if it.Text != nil {
		log.Printf("Text: %s\n", it.GetText())
	}
}
Exemple #3
0
func main() {
	flag.Parse()
	db, err := leveldb.OpenFile(*dbpath, nil)
	check(err)
	defer db.Close()
	iter := db.NewIterator(nil, nil)
	for iter.Next() {
		var it gohn.Item
		err := proto.Unmarshal(iter.Value(), &it)
		check(err)
		if it.GetTitle() != "" {
			fmt.Printf("%d: %s\n", it.GetId(), it.GetTitle())
		}
	}
}