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) }
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()) } }
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()) } } }