From f5f59b3750039fbc772e3c4fb44457f418260ac4 Mon Sep 17 00:00:00 2001 From: John Shahid Date: Tue, 1 Apr 2014 11:31:42 -0400 Subject: [PATCH] add a func to get the version of the loaded leveldb --- README.md | 2 +- leveldb_test.go | 4 ++++ version.go | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 version.go diff --git a/README.md b/README.md index bb66825..3ea196b 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ You'll need the shared library build of [LevelDB](http://code.google.com/p/leveldb/) installed on your machine. The current LevelDB will build it by default. -The minimum version of LevelDB required is currently 1.6. If you require the +The minimum version of LevelDB required is currently 1.7. If you require the use of an older version of LevelDB, see the [fork of levigo for LevelDB 1.4](https://github.com/jmhodges/levigo_leveldb_1.4). Prefer putting in the work to be up to date as LevelDB moves very quickly. diff --git a/leveldb_test.go b/leveldb_test.go index 523a5c5..0d6930b 100644 --- a/leveldb_test.go +++ b/leveldb_test.go @@ -16,6 +16,10 @@ func init() { // This testcase is a port of leveldb's c_test.c. func TestC(t *testing.T) { + if GetLevelDBMajorVersion() <= 0 { + t.Errorf("Major version cannot be less than zero") + } + dbname := tempDir(t) defer deleteDBDirectory(t, dbname) env := NewDefaultEnv() diff --git a/version.go b/version.go new file mode 100644 index 0000000..cda7b69 --- /dev/null +++ b/version.go @@ -0,0 +1,15 @@ +package levigo + +/* +#cgo LDFLAGS: -lleveldb +#include "leveldb/c.h" +*/ +import "C" + +func GetLevelDBMajorVersion() int { + return int(C.leveldb_major_version()) +} + +func GetLevelDBMinorVersion() int { + return int(C.leveldb_minor_version()) +}