Skip to content

Instantly share code, notes, and snippets.

@islishude
Created February 28, 2019 08:01
Show Gist options
  • Save islishude/cfd517c3cb36f297adb9cc56e5eb5574 to your computer and use it in GitHub Desktop.
Save islishude/cfd517c3cb36f297adb9cc56e5eb5574 to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"encoding/gob"
"github.com/syndtr/goleveldb/leveldb"
)
const dbpath = ".leveldb"
var key = []byte("key")
type trx struct {
Txid string
To string
From string
Value float64
}
var txdata = trx{Txid: "txid", To: "addr", From: "src", Value: 123}
func main() {
db, err := leveldb.OpenFile(dbpath, nil)
if err != nil {
panic(err)
}
defer db.Close()
var buf bytes.Buffer
if err := gob.NewEncoder(&buf).Encode(txdata); err != nil {
panic(err)
}
data, err := db.Get(key, nil)
if err != nil {
panic(err)
}
nbuf := bytes.NewReader(data)
var nutxo trx
if err := gob.NewDecoder(nbuf).Decode(&nutxo); err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment