Nakama Go Runtime
Nakama Go Runtime uses the Go Plugin package to run custom server logic. If you've used the existing Nakama Lua Runtime, then it should be pretty straight forward to use the Go Runtime as the APIs are very similar.
You can find more information about the Nakama Go Runtime on the website.
Plugin depedencies
You'll need to ensure that you have heroiclabs/nakama/rtapi
and heroiclabs/nakama/runtime
available in your GOPATH
. You can then begin to implement the neccessary function that Nakama needs to interact with your plugin. Ensure that you have implemented the InitModule
function as Nakama uses this as the entry point to your plugin.
You can find more information about the Nakama Go Runtime on the website.
Build plugin
Binary
If you are running Nakama as a binary, then you can easily build your plugin and instruct Nakama to load the shared object.
To do so, simply run the following command to build the plugin:
go build -buildmode=plugin
This will produce a .so
file (platform dependant) that you'll need to place in the modules directory of Nakama. You can then start Nakama as usual.
Docker
If you are running Nakama through the Docker image, you'll need to also compile the plugin via the provided docker builder recipe. This is a known limitation in the Go compile toolchain as it cannot cross-compile plugins.
Copy the content of the plugin.Dockerfile
onto your system and run the following command:
docker build <DockerContext> --file "/absolute/path/to/plugin.Dockerfile" --build-arg src="relative/path/to/<ModuleName>"
- Ensure that you change the
<DockerContext>
folder with the absolute path to your project folder.
- Ensure that the
<ModuleName>
folder is inside the <DockerContext>
project folder you referenced above.
- Ensure that you update the absolute path of the
plugin.Dockerfile
.
For example:
docker build "/go/src/github.com/heroiclabs/nakama" --file "/home/plugin.Dockerfile" --build-arg src="sample_go_module"
Docker will then compile your plugin. To load the compiled plugin, you'll need to extract the shared object from the docker container:
docker run --rm --entrypoint cat <ContainerId> /go/build/<ModuleName>.so > /home/<ModuleName>.so
Make sure that you change the <ContainerId>
with the actual container identifier. You can do this by running
docker images
The compiled shared object file is on your desktop. You can move the shared object to a folder that you've assigned as your runtime module folder. Have a look at this for more info.