diff --git a/.gitignore b/.gitignore index 8c033c5..73fbcb2 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ _* [568].out *.cgo*.c *.cgo*.go +tags diff --git a/README b/README deleted file mode 100644 index f53af52..0000000 --- a/README +++ /dev/null @@ -1,4 +0,0 @@ -Check out https://wiki.ubuntu.com/gozk - -Forked from https://github.com/youtube/vitess/tree/master/third_party/go/launchpad.net/gozk/zookeeper -to fix panic issues in some of the watch functions. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e2af762 --- /dev/null +++ b/README.md @@ -0,0 +1,65 @@ +# gozk - Go zookeeper library via C bindings + +Forked from https://github.com/youtube/vitess/tree/master/third_party/go/launchpad.net/gozk/zookeeper + +## Requirements + +- zookeeper c library headers: when installed via homebrew you'll find the includes under `/opt/homebrew/include` and the shared libraries in `/opt/homebrew/lib/`. Other + systems such as Linux use different paths but are likely to place them under `/usr/include` and `/usr/lib`. +- C compiler + +The default flags defined in zk.go **should be sufficient** for builds on Linux or MacOSX. But If you zookeeper includes and shared libraries are not in the default +search locations (`/usr/include` and `/usr/lib`) you'll have to set environment variables to point the compiler at the right path. For example when using homebrew, +you'll need to specify: + +``` +export CGO_CFLAGS='-I/opt/homebrew/include/zookeeper' +export CGO_LDFLAGS='-L/opt/homebrew/lib' +``` + +On Debian Linux, used by the official go docker container, you'll needthe following libraries: + +* `libzookeeper-mt-dev`: header files +* `libzookeeper-mt2`: shared libraries + +Set the `CGO` flags: + +``` +export CGO_CFLAGS='-I/usr/include/zookeeper' +export CGO_LDFLAGS='-L/usr/lib/aarch64-linux-gnu' +``` + +Then: + +``` +go build +``` + +### Build Errors + +#### `zookeeper.h` not found +Error message looks like this: +``` +./zk.go:21:11: fatal error: zookeeper.h: No such file or directory + 21 | // #include + | ^~~~~~~~~~~~~ +compilation terminated. +``` + +The include search path does not include the zookeeper includes. Check that `CGO_CFLAGS=-I` is set to a directory that contains the zookeeper includes. + +#### `ld: library not found` +Error message: +``` +ld: library not found for -lzookeeper_mt +collect2: error: ld returned 1 exit status +``` + +The linker can't find the shared library. Ensure that `CGO_LDFLAGS=-L` points to a directory that contains the zookeeper libraries. + +## Historic Notes + +Check out https://wiki.ubuntu.com/gozk + +Forked from https://github.com/youtube/vitess/tree/master/third_party/go/launchpad.net/gozk/zookeeper +to fix panic issues in some of the watch functions. diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..227c517 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/Shopify/gozk + +go 1.16 + +require launchpad.net/gocheck v0.0.0-20140225173054-000000000087 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..9c4b05c --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +launchpad.net/gocheck v0.0.0-20140225173054-000000000087 h1:Izowp2XBH6Ya6rv+hqbceQyw/gSGoXfH/UPoTGduL54= +launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM= diff --git a/zk.go b/zk.go index f5ba0c4..3222950 100644 --- a/zk.go +++ b/zk.go @@ -8,13 +8,13 @@ // package zookeeper -/* -#cgo CFLAGS: -I/usr/include/c-client-src -I/usr/include/zookeeper -#cgo LDFLAGS: -lzookeeper_mt - -#include -#include "helpers.h" -*/ +// #cgo CFLAGS: -DTHREADED -I/usr/include/zookeeper +// #cgo darwin CFLAGS: -DTHREADED -I/opt/homebrew/include/zookeeper +// #cgo LDFLAGS: -lzookeeper_mt +// #cgo darwin LDFLAGS: -L/opt/homebrew/lib +// +// #include +// #include "helpers.h" import "C" import (