A Go wrapper for LevelDB, forked from jmhodges/levigo.
This fork makes levigo go-gettable by including the C++ source for LevelDB
and building it with the Go code. LevelDB and Snappy are both compiled
and linked statically, so while you will not need them installed on your
target machine, you should have a roughly compatible version of libstdc++
.
This package currently includes LevelDB 1.19, and supports Linux and OS X. It should work on Go 1.5 or greater.
This package supports Linux and OS X.
You'll need gcc and g++. Then:
go get github.com/DataDog/leveldb
This will take a long time as it compiles the LevelDB source code along with the Go library.
To avoid waiting for compilation every time you want to build your project, you can run:
go install github.com/DataDog/leveldb
- Overwrite source in
./deps/snappy/
make link_snappy
If nothing significant in snappy has changed, things should JustWork™
The embedded LevelDB source code is located in deps/leveldb
. In order to get
go build
to compile LevelDB, we symlink the required LevelDB source files to
the root directory of the project. These symlinks are prefixed with deps_
.
To change the embedded version of LevelDB, do the following:
rm deps_*.cc
- Replace
deps/leveldb
with the source code of the desired version of LevelDB - On Linux, run
./deps/leveldb/build_detect_platform linux.mk build_flags
- On OS X, run
./deps/leveldb/build_detect_platform darwin.mk build_flags
cat build_flags/*
, take a quick look at the new compiler and linker flags and see if there are any flags we're missing incgo_flags_*.go
. If so, add them.make link_leveldb
- On OS X and Linux, run
go build
and verify that everything compiles.
note I couldn't get build_detect_platform
to run as advertised above -- j
Comparators and WriteBatch iterators must be written in C in your own library. This seems like a pain in the ass, but remember that you'll have the LevelDB C API available to your in your client package when you import levigo.
An example of writing your own Comparator can be found in https://github.com/DataDog/leveldb/blob/master/examples.