Question

From http://code.google.com/p/leveldb/, it seems not explicit or easy to use LevelDB with Go. But I really want to know how to use it in Go.

Could anyone give me a clue?

Was it helpful?

Solution

Use leveldb-go, ported by the Go Authors.

OTHER TIPS

Here is a Go implementation of LevelDB https://github.com/syndtr/goleveldb

Here is how to use it:

go get github.com/syndtr/goleveldb/leveldb

Create or open database:

db, err := leveldb.OpenFile("path/to/db", nil)
...
defer db.Close()
...

Read or modify the database content:

data, err := db.Get([]byte("key"), nil)
...
err = db.Put([]byte("key"), []byte("value"), nil)
...
err = db.Delete([]byte("key"), nil)
...

Use levigo - a Golang wrapper around the C++ version of LevelDB.

The file levigo/leveldb_test.go gives you an example of how to use levigo.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top