Golang Client

If you prefer videos:

Introduction

Sometime last year, we released our initial blog post which relayed information on how to get up and running using the GridDB Go Client. Because of some changes to both the process and installation, we’ve decided to release an update.

As a small note on the Go client before you begin work: please know that the array type for GridDB is not yet available for the Go Client. If your project absolutely requires the array type, please use the Python/C/Java Client instead.

Installation

Install c_client

This small excerpt is taken from our Node.js Client Blog

The GridDB c_client (a preqrequisite to using the Go Client) can be found here: https://github.com/griddb/c_client. The c_client installation has been simplified since the last blog; instead of compiling from source yourself, there is now an RPM available for your convenience (the releases page can be found here). So to get started simply wget the latest RPM and install.

$ wget \
https://github.com/griddb/c_client/releases/download/v4.2.0/griddb_c_client-4.2.0-1.linux.x86_64.rpm

then we need to actually install the rpm

$ sudo rpm -ivh griddb_c_client-4.2.0-1.linux.x86_64.rpm

and now the c_client is installed and ready in your /usr/ directory. That was easy!

With the C Client installed, we will need to point our LD_LIBRARY_PATH environment variable to the directory which contains the newly made files.

$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/griddb_c_client-4.2.0/lib

$ export LIBRARY_PATH=$LIBRARY_PATH:/usr/griddb_c_client-4.2.0/lib

Install Go Client

To install the Go Client is a bit more work as it has a couple of dependencies. Obviously the Go language itself is needed, so please install that first and set your environment. While you’re setting your environment, please note that the following is mandatory for the Go Client to run successfully:

$ export GODEBUG=cgocheck=0

This will disable Go’s default behavior of abiding by certain C pointer rules (default is cgocheck=1); you can learn more about this option here: https://golang.org/cmd/cgo/#hdr-Passing_pointers.

Next let’s install some prereqs. If you would like to simply copy and paste the next commands, please switch the root user.

First up is PCRE:

$ wget https://sourceforge.net/projects/pcre/files/pcre/8.39/pcre-8.39.tar.gz
$ tar xvfz pcre-8.39.tar.gz
$ cd pcre-8.39
$ ./configure
$ make
$ make install

And next is SWIG:

$ wget https://prdownloads.sourceforge.net/swig/swig-3.0.12.tar.gz
$ tar xvfz swig-3.0.12.tar.gz
$ cd swig-3.0.12
$ ./configure
$ make
$ make install

Now let’s install the actual Go Client from github: https://github.com/griddb/go_client/releases

$ wget \
https://github.com/griddb/go_client/archive/0.8.1.tar.gz

and unzip the tar ball and make

$ tar xvzf 0.8.1.tar.gz
$ cd go_client-0.8.1
$ make

Now that the Go Client is made, let’s point our GOPATH to the go client so that we can properly use the Go client with our code.

$ export GOPATH="${GOPATH}:/home/lib/go_client-0.8.1"

Possible Issues Installing

Issues Making

One common issue encountered is the following error:

go install github.com/griddb/go_client
can't load package: package github.com/griddb/go_client:
  cannot find package "github.com/griddb/go_client"

This arises out of not having your environment properly set. If this happens, run a make clean within the directory to start from scratch, and make sure that the CGOCHECK is set to 0 (disabled) and that the LD_LIBRARY_PATH is pointing to your GridDB C Client (a prereq/dependency for this package).

Issuing Importing Package Into Code

Another potential sore spot has to do with how Go organizes its remote packages (libraries outside the standard library). In Go, remote packages are fetched with the go get command which then places them in yourgopath/src/packagerepository/accountname/package. So if I download the echo web framework from Labstack for example, the code will auto-placed into /home/israel/go/src/github.com/labstack/echo. So when you import the echo web framework in your code import "github.com/labstack/echo", Go will look into these directories to pull the code.

Knowing this, a developer would likely build the Go Client, place it into the proper directory using known rules, and attempt to go build their project. Except now they’re hit with a:

can't load package: package github.com/griddb/go_client: no Go files in /home/israel/go/src/github.com/griddb/go_client

Luckily for us, this has an easy fix. To get this to work, we just need to move our directory out of the default Go path and anywhere else (/home/lib/ for example) and then point our Go Path to this new location.

$ export GOPATH="${GOPATH}:/home/lib/go_client-0.8.1

Usage

Because the changes we wanted to highlight were more towards installation, we will kindly refer you to our previous blog post for information regarding actual Go code.

If you have any questions about the blog, please create a Stack Overflow post here https://stackoverflow.com/questions/ask?tags=griddb .
Make sure that you use the “griddb” tag so our engineers can quickly reply to your questions.