NOTE The Public Preview of the Ditto Go SDK can be used for exploratory development and prototypes. Refer to the documentation for supported features. Future versions of the Ditto Go SDK may not be compatible with the current preview API.
In the directory containing your application's go.mod file, run these commands to add the Ditto Go SDK and its dependencies:
go get github.com/getditto/ditto-go-sdk/v5@latest
go mod tidyThen, in any Go source file that uses the Ditto SDK, add this import:
import "github.com/getditto/ditto-go-sdk/v5/ditto"API documentation for the Go SDK can be found at https://software.ditto.live/go/Ditto/5.0.0-go-preview.3/docs/github.com/getditto/ditto-go-sdk/v5/ditto/index.html.
A native library provides Ditto Edge Sync Platform functionality, and must be downloaded and linked into any application that uses the Ditto Go SDK.
Download Ditto.tar.gz and unpack an archive containing the libdittoffi.so (Linux) or libdittoffi.dylib (macOS) shared library for your operating system and CPU architecture.
curl -O https://software.ditto.live/go/Ditto/5.0.0-go-preview.3/dist/libdittoffi-linux-x86_64.tar.gz && tar xvfz libdittoffi-linux-x86_64.tar.gzcurl -O https://software.ditto.live/go/Ditto/5.0.0-go-preview.3/dist/libdittoffi-linux-aarch64.tar.gz && tar xvfz libdittoffi-linux-aarch64.tar.gzcurl -O https://software.ditto.live/go/Ditto/5.0.0-go-preview.3/dist/libdittoffi-macos-aarch64.tar.gz && tar xvfz libdittoffi-macos-aarch64.tar.gzWhen you build your application that uses the Ditto Go SDK, the linker needs to be able to find the native library.
The shared libdittoffi.so library will automatically be linked to by the Go SDK if it is in one of these locations:
/usr/local/lib/usr/lib
Copy the unpacked libdittoffi.so to one of these locations for automatic linking.
If your libdittoffi.so is located somewhere else, you can pass that path to go build via the -ldflags option when you build your application.
go build -ldflags='-extldflags "-L/path/to/my/lib/directory"'The shared libdittoffi.dylib library will automatically be linked to by the Go SDK if it is in one of these locations:
/usr/local/lib/usr/lib
Copy the unpacked libdittoffi.dylib to one of these locations for automatic linking.
If your libdittoffi.dylib is located somewhere else, you can pass that path to go build via the -ldflags option when you build your application.
go build -ldflags='-extldflags "-L/path/to/my/lib/directory"'When an app that uses the Ditto Go SDK is run, the system must be able to find and load the native library.
Ubuntu/Debian will search in these directories at runtime by default:
/lib/lib64/usr/lib/usr/lib64/usr/local/lib
If you don't deploy the libdittoffi.so library in one of those directories, set the LD_LIBRARY_PATH environment variable to the appropriate directory when running your application. For example:
LD_LIBRARY_PATH=/path/to/my/lib/directory ./myappor
export LD_LIBRARY_PATH=/path/to/my/lib/directory
./myappmacOS will search in these directories at runtime by default:
/usr/lib/usr/local/lib
If you don't deploy the libdittoffi.dylib library in one of those directories, set the DYLD_LIBRARY_PATH environment variable to the appropriate directory when running your application. For example:
DYLD_LIBRARY_PATH=/path/to/my/lib/directory ./myappor
export DYLD_LIBRARY_PATH=/path/to/my/lib/directory
./myapp