Note: The Go API works on Windows x64 and Unix-like operating systems. 32-bit Windows is not currently supported.
Warning: Early stage development version. Use at your own risk.
Warning: Go1.9.0 is not supported. If you encounter a compilation problem with time.go please upgrade.
Go API for quasardb.
- Go compiler and tools
- quasardb daemon
- quasardb C API version corresponding to the OS you use
- The version of the quasardb C API must match the current git branch, the master branch corresponds to the nightly C API
go get -d github.com/bureau14/qdb-api-go
- Extract the downloaded C API into
$GOPATH/src/github.com/bureau14/qdb-api-go/qdb
export QDB_SERVER_PATH=/path/to/qdb-server/bin
# a path to a dir containing qdbd, qdb_cluster_keygen and qdb_user_add executablescd $GOPATH/src/github.com/bureau14/qdb-api-go
go test
export QDB_SERVER_PATH=/path/to/qdb-server/bin
# a path to a dir containing qdbd, qdb_cluster_keygen and qdb_user_add executablescd $GOPATH/src/github.com/bureau14/qdb-api-go
go test -coverprofile=coverage.out
go tool cover -html=coverage.out
# if you want to see coverage detail in a browser
mkdir $GOPATH/src/<PROJECT>
- Extract the downloaded C API into
$GOPATH/src/<PROJECT>/qdb
- Ensure quasardb C library is in the
DYLD_LIBRARY_PATH
:export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$GOPATH/src/<PROJECT>/qdb/lib
If you encounter any problems, please create an issue in the bug tracker.
Assuming a non secured database (see "Setup a secured connection" section for secured databases)
import qdb "github.com/bureau14/qdb-api-go"
import "time"
func main() {
handle, err := qdb.SetupHandle("qdb://127.0.0.1:2836", time.Duration(120) * time.Second)
if err != nil {
// do something with error
}
defer handle.Close()
blob := handle.Blob("alias")
content := []byte("content")
err = blob.Put(content, qdb.NeverExpires())
if err != nil {
// do something with error
}
contentUpdate := []byte("updated content")
err = blob.Update(contentUpdate, qdb.NeverExpires())
if err != nil {
// do something with error
}
blob.Remove()
}
The following tests samples are presuming you import as specified in the previous example. The error checking will be omitted for brevity.
handle, err := qdb.SetupHandle("qdb://127.0.0.1:2836", time.Duration(120) * time.Second)
// alternatively:
handle := qdb.MustSetupHandle("qdb://127.0.0.1:2836", time.Duration(120) * time.Second)
handle, err := qdb.SetupSecureHandle("qdb://127.0.0.1:2836", "/path/to/cluster_public.key", "/path/to/user_private.key", time.Duration(120) * time.Second, qdb.EncryptNone)
// alternatively:
handle := qdb.MustSetupSecureHandle("qdb://127.0.0.1:2836", "/path/to/cluster_public.key", "/path/to/user_private.key", time.Duration(120) * time.Second, qdb.EncryptNone)
This could prove useful if you need to manage the flow of creation of your handle.
handle, err := qdb.NewHandle()
// Set timeout
err = handle.SetTimeout(time.Duration(120) * time.Second)
// Set encryption if enabled server side
err = handle.SetEncryption(qdb.EncryptAES)
// add security if enabled server side
clusterKey, err := ClusterKeyFromFile("/path/to/cluster_public.key")
err = handle.AddClusterPublicKey(clusterKey)
user, secret, err := ClusterKeyFromFile("/path/to/cluster_public.key")
err = handle.AddUserCredentials(user, secret)
// connect
err = handle.Connect("qdb://127.0.0.1:2836)