سؤال

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?

هل كانت مفيدة؟

المحلول

Use leveldb-go, ported by the Go Authors.

نصائح أخرى

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top