t1k:nakama:plugin
| Field | Value |
|---|---|
| Module | base |
| Version | 1.6.2 |
| Effort | low |
| Tools | — |
Keywords: build, go, InitModule, nakama, plugin, runtime, shared object
How to invoke
Section titled “How to invoke”/t1k:nakama:pluginNakama Plugin Development
Section titled “Nakama Plugin Development”Overview
Section titled “Overview”Nakama server loads custom Go code as shared-object plugins (.so). The plugin must export an InitModule function and match the host binary’s exact dependency versions.
Key Patterns
Section titled “Key Patterns”InitModule Entry Point
Section titled “InitModule Entry Point”func InitModule(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, initializer runtime.Initializer) error { // Register RPCs, hooks, matches here return nil}Build Command
Section titled “Build Command”go build -trimpath -buildmode=plugin -o modules/backend.so ./modulesRuntime APIs
Section titled “Runtime APIs”runtime.Initializer— register RPCs (RegisterRpc), hooks (RegisterBefore*,RegisterAfter*), matchesruntime.NakamaModule— authenticate users, read/write storage, send notificationsruntime.Logger— structured logging (Info,Warn,Error,Debug)runtime.RUNTIME_CTX_*— context keys for user ID, session ID, env vars
Dependency Pinning
Section titled “Dependency Pinning”Go plugins require exact binary compatibility with the host Nakama binary. All shared dependencies (protobuf, grpc, golang.org/x/*) must match pinned versions. See DEPENDENCY_PINS.md.
Gotchas
Section titled “Gotchas”- CRITICAL: Never run
go get -uon shared deps — will break plugin loading - Plugin
.soand Nakama binary must be compiled with the same Go version InitModuleruns once at startup — all registration must happen here, not lazily-trimpathflag is required to avoid path-dependent build artifacts- The module directory must contain
main.gowithpackage main - Plugin ABI mismatch: Go version used to compile plugin MUST exactly match Nakama binary’s Go version. Even patch versions matter.
-buildmode=pluginrequired: Without this flag, the binary won’t load as a Nakama plugin.- Dependency pinning: All shared deps (protobuf, gRPC) must match Nakama’s
go.sum. Usego mod tidyand verify checksums.
Checklist
Section titled “Checklist”-
go.modmodule path matches expected import path - All pinned deps match DEPENDENCY_PINS.md versions
- Build succeeds:
go build -trimpath -buildmode=plugin -o modules/backend.so ./modules -
InitModulereturns nil on success, wrapped error on failure - No
fmt.Print*orlog.*— useruntime.Loggerexclusively