Created
February 28, 2019 08:01
-
-
Save islishude/cfd517c3cb36f297adb9cc56e5eb5574 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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