nakama

package module
v0.8.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 26 Imported by: 3

README

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
  • 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

Documentation

Overview

Package nakama is a nakama http and realtime websocket client.

Example
const id = "6d0c9e83-8385-48a8-8601-060b8f6a3bf6"
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// create client
cl := nakama.New(nakama.WithServerKey("nakama-go_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

Index