This package uses pkg-config to find libyottadb.so. The appropriate file is generated by YottaDB r1.24 and greater via ydbinstall (any other installation methods do not install the yottadb.pc file).
If you need to manually generate the yottadb.pc file the contents should look something similar to:
prefix=/usr/local/lib/yottadb/r124
exec_prefix=${prefix}
includedir=${prefix}
libdir=${exec_prefix}
Name: YottaDB
Description: YottaDB database library
Version: r1.24
Cflags: -I${includedir}
Libs: -L${libdir} -lyottadb -Wl,-rpath,${libdir}
Change the prefix to the correct path for your environment.
NOTE: you cannot use environment variables for the prefix path (e.g. $ydb_dist) it must be a fully qualified path.
You can also override the path used by pkg-config to find yottadb.pc with the environment variable PKG_CONFIG_PATH
and a path to where the yottadb.pc file resides.
Using the package:
go mod init myprogram
go get lang.yottadb.com/go/yottadb
Build the package:
go build lang.yottadb.com/go/yottadb
Before running code using YottaDB or running the YottaDB tests, you need to make sure you have all the needed environment variables configured. The best way to do this is by sourcing ydb_env_set:
source $(pkg-config --variable=prefix yottadb)/ydb_env_set
Run the tests:
go get -t lang.yottadb.com/go/yottadb
go test lang.yottadb.com/go/yottadb
To use a local development version of YDBGo
mkdir -p $GOPATH/src/lang.yottadb.com/go/yottadb
git clone https://gitlab.com/YottaDB/Lang/YDBGo.git $GOPATH/src/lang.yottadb.com/go/yottadb
ln -s ../../pre-commit .git/hooks
The Dockerfile/container included in this repo pre-installs YottaDB and the Go language and runs on an Ubuntu image. Some basic development tools are also pre-installed (git, gcc, make, etc).
If there is a better way to create the Docker container that suits the community's needs, please file an issue.
There are two modes that you can use the Docker container in:
- Use a database created by using the defaults created by running the YottaDB
ydb_env_set
script which sets up some sane defaults. - Use a database manually created upon running the container - this still runs
ydb_env_set
, but runs in such a way that some control is still given to the user
To build the container run:
docker build . -t ydbgo
This example command will map the current directory into the container under the /data directory and will run a sample 3n+1 application that contains a Go based webserver. This requires that you have built the docker container already and have cloned the threenp1-viewer repository and your current directory is the threenp1-viewer
subdirectory of the cloned repo - probably something like threenp1-viewer/threenp1-viewer.
# Note that the current directory should be the `threenp1-viewer` subdirectory of the cloned repo before running the below command - probably something like threenp1-viewer/threenp1-viewer
docker run -it -p3000:3000 -v `pwd`:/data ydbgo /bin/bash -c "source \$ydb_dist/ydb_env_set && go get -d . && go build && echo 'Type a number then press <ENTER> twice' && \$ydb_dist/mumps -r simpleapithreen1f && echo 'Open a web browser to http://localhost:3000/static' && sleep 2 && ./data"
This example command will map the current directory into the container under the /data directory, create a new database using some manually provided defaults, and will run a 3n+1 application that contains a Go based webserver. This requires that you have built the docker container already and have cloned the threenp1-viewer repository and your current directory is the threenp1-viewer
subdirectory of the cloned repo - probably something like threenp1-viewer/threenp1-viewer.
# Note that the current directory should be the `threenp1-viewer` subdirectory of the cloned repo before running the below command - probably something like threenp1-viewer/threenp1-viewer
docker run -it -p3000:3000 -v `pwd`:/data ydbgo /bin/bash -c "unset ydb_routines && source \$ydb_dist/ydb_env_set && echo change -s DEFAULT -FILE=/data/mumps.dat | /opt/yottadb/current/mumps -run ^GDE && \$ydb_dist/mupip create && go get -d . && go build && echo 'Type a number then press <ENTER> twice' && \$ydb_dist/mumps -r simpleapithreen1f && echo 'Open a web browser to http://localhost:3000/static' && sleep 2 && ./data"