Skip to content

Nakama web and realtime client for Go (works with WASM)

License

Notifications You must be signed in to change notification settings

ascii8/nakama-go

Repository files navigation

About

A Go web and realtime client package for the Nakama game server. Works with WASM builds.

Tests Go Report Card Reference Releases

Using

go get github.com/ascii8/nakama-go

Quickstart

package nakama_test

import (
	"context"
	"fmt"
	"log"

	"github.com/ascii8/nakama-go"
)

func Example() {
	const id = "6d0c9e83-8385-48a8-8601-060b8f6a3bf6"
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()
	// create client
	cl := nakama.New(nakama.WithServerKey("apitest_server"))
	// authenticate
	if err := cl.AuthenticateDevice(ctx, id, true, ""); err != nil {
		log.Fatal(err)
	}
	// retrieve account
	account, err := cl.Account(ctx)
	if err != nil {
		log.Fatal(err)
	}
	// list devices on the account
	for _, d := range account.Devices {
		fmt.Println("id:", d.Id)
	}
	// Output:
	// id: 6d0c9e83-8385-48a8-8601-060b8f6a3bf6
}

Examples

See github.com/ascii8/xoxo-go for a demonstration of end-to-end unit tests using nktest, and "real world" examples of pure Go clients (e.g., Ebitengine) built using this client package.

See the Go package documentation for other examples.

Notes

Run browser tests:

# setup wasmbrowsertest
$ go install github.com/agnivade/wasmbrowsertest@latest
$ cd $GOPATH/bin && ln -s wasmbrowsertest go_js_wasm_exec

# run the wasmtests
$ cd /path/to/nakama-go/wasmtest
$ GOOS=js GOARCH=wasm go test -v

Related Links

  • github.com/ascii8/nktest - a Nakama test runner
  • github.com/ascii8/xoxo-go - a pure Go version of Nakama's XOXO example, demonstrating end-to-end unit tests, and providing multiple example clients using this package. Has example Ebitengine client