Go
Your game server reaches /server/v1 through the Go server client: the module
rudder.build/server and the packages rudder server generate --lang go writes from a release.
It uses the standard library only.
Install
Section titled “Install”The module path is resolved through the go-import meta tag of rudder.build/server; set
GOPRIVATE=rudder.build so the Go command fetches it from the Rudder Gitea.
Generate the client
Section titled “Generate the client”In the Go module of the game server:
rudder server generate --lang go --output ./rudderclient --package rudderclient \ --game-address https://api.rudder.build [--environment staging|prod]The client follows a release, not the draft. It writes a root package with a Client and one
subpackage per module (stores, battlepass), a method per function, the functions marked
server included, and the types of their arguments and results. Every method names the player
first. Generate it again when a release changes a function or a type.
import ( "context"
"game/rudderclient" "game/rudderclient/inventory" "rudder.build/server")
client := rudderclient.New(server.Options{ServerKey: os.Getenv("RUDDER_SERVER_KEY")})
environment, err := client.Server.Environment(ctx)purchase, err := client.Stores.Buy(ctx, playerID, rudderclient.StoresBuyArguments{Offer: "pumpkin-pack"}, nil)granted, err := client.Inventory.Grant(ctx, playerID, inventory.Goods{Item: "potion"}, nil)
err = client.Server.SetPlayerProfile(ctx, playerID, server.Profile{Nickname: "Ada", Avatar: "https://example.com/ada.png"})err = client.Server.BanPlayer(ctx, playerID, server.Ban{Until: time.Now().Add(time.Hour), Reason: "cheating"})err = client.Server.UnbanPlayer(ctx, playerID)The root Client holds Server *server.Client and a client per module: the profile, the ban
and the environment live on client.Server, the functions of a module on client.<Module>.
- Environment.
Environment(ctx)answersstagingorprod, the environment of the server key. The header of the generated files names the environment they were generated from. - Calls. A mutation sends an
Idempotency-Key, generated for each call unlessserver.MutationOptions{IdempotencyKey: ...}is passed. A banned player is refused to the game client only. - Errors. A refused call answers
*server.Error; read it witherrors.As. - Retries. A request that got no answer or the answer
try_againis sent again after theRetry-Afterit gave or a short backoff, at most five times, with the same key. 429 is not retried. Pass acontext.Contextto cancel.