The Go SDK is currently in Public Preview with version
5.0.0-go-preview.3. If you encounter any issues or need assistance, please contact Ditto Support.Adding the Ditto Go SDK to a Go Application
The Ditto Go SDK is available via a public GitHub repository: https://github.com/getditto/ditto-go-sdk/. In the directory containing your application’sgo.mod file, run these commands to add the Ditto Go SDK and its dependencies:
ditto package:
Go
Installing the Ditto Go SDK Native Library
A native library provides Ditto Edge Sync Platform functionality, and must be linked into any application that uses the Ditto Go SDK.Downloading and Unpacking the Ditto Library
DownloadDitto.tar.gz and unpack an archive containing the libdittoffi.so (Linux) or libdittoffi.dylib (macOS) shared library:
Linking to the Ditto Shared Library at Build Time
When you build your application that uses the Ditto Go SDK, the linker needs to be able to find the native library.Linux
The sharedlibdittoffi.so library will automatically be linked to by the Go SDK if it is in one of these locations:
/usr/local/lib/usr/lib
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.
macOS
The sharedlibdittoffi.dylib library will automatically be linked to by the Go SDK if it is in one of these locations:
/usr/local/lib/usr/lib
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.
Linking to the Ditto Shared Library at Run Time
When an app that uses the Ditto Go SDK is run, the system must be able to find and load the native library.Linux
Ubuntu/Debian will search in these directories at runtime by default:/lib/lib64/usr/lib/usr/lib64/usr/local/lib
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:
macOS
The macOS dynamic linker (dyld) checks environment variables during launch to determine where to find dynamic libraries. You can setDYLD_LIBRARY_PATH or DYLD_FALLBACK_LIBRARY_PATH to a colon-separated list of directories that contain shared libraries.
Alternatively, you can use the macOS install_name_tool utility to embed shared-library locations in the executable.
See the man pages for dyld and install_name_tool for details.
Using DYLD_LIBRARY_PATH
Set theDYLD_LIBRARY_PATH environment variable to the appropriate directory when running your application. For example:
Using DYLD_FALLBACK_LIBRARY_PATH
DYLD_FALLBACK_LIBRARY_PATH will be used by the loader if the library is not found in DYLD_LIBRARY_PATH.
In older versions of macOS, if this variable was unset the default value was /usr/local/lib:/usr/lib. However, in versions of macOS after Fall 2023, there is no longer a default value.
Using install_name_tool
Theinstall_name_tool utility (included with macOS) can be used to add or change the rpaths recorded in an executable program. The rpaths will be searched, making setting of DYLD_LIBRARY_PATH unnecessary.
For example, if you want to search for shared libraries in the same directory containing the executable, do this:
/usr/local/lib, do this: