Use Extend Codegen CLI to generate Go Extend SDK Module for Extend Service Extension
Overview
This article provides a step-by-step guide on how to generate a custom service module for the Go Modular Extend SDK using the Extend Codegen CLI template pack.
A custom service module allows developers to leverage the Go Modular Extend SDK to interact with custom service APIs. This includes services created with the Extend Service Extension, as well as any other custom service that provides an OpenAPI 2.0 specification..
The Extend Codegen CLI template pack consists of a Makefile and some Jinja template files. To generate the necessary code, simply invoke a single make command. This command triggers the Extend Codegen CLI to process the Jinja template files alongside an OpenAPI 2.0 JSON file, which outlines the custom service APIs, to generate the corresponding code.
When following this guide, be sure to use the Go Modular Extend SDK instead of the Go Extend SDK.
Prerequisites
-
Windows 11 WSL2 or Linux Ubuntu 22.04 with the following tools installed.
a. Bash
bash --version
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
...b. Make
- To install from Ubuntu repository, run:
sudo apt update && sudo apt install make.
make --version
GNU Make 4.3
...c. Docker (Docker Engine v23.0+)
- To install from Ubuntu repository, run:
sudo apt update && sudo apt install docker.io docker-buildx docker-compose-v2. - Add your user to
dockergroup:sudo usermod -aG docker $USER. - Log out and log back in so that the changes take effect.
docker version
...
Server: Docker Desktop
Engine:
Version: 24.0.5
... - To install from Ubuntu repository, run:
-
Extend Codegen CLI template pack zip for Go.
-
A valid OpenAPI 2.0 JSON file for your custom service.
infoIf your custom service uses the Extend Service Extension, an OpenAPI 2.0 JSON file is automatically generated when the app is deployed in AccelByte Gaming Services (AGS). To access it, open the AGS
Admin Portal, navigate to your app'sApp Detailspage, clickOpen API Documentation, and find the JSON file link at the top of the Swagger UI page.Alternatively, if you need to get the OpenAPI 2.0 JSON file before deploying your app in AGS, see here.
Generate Go Extend SDK Module for Extend Service Extension
-
Place the OpenAPI 2.0 JSON file for your custom service in the
extend-service-extension-module-sdk/specfolder. In this example, the file is namedguild.json./path/to/my/extend-service-extension-module-sdk/
|__ spec/
|__ guild.jsonimportantThe Extend Codegen CLI template pack uses the OpenAPI 2.0 JSON file name as an identifier for your service: You can rename the file according to your preferences, but we recommend using all lowercase alphabets (a-z) to avoid issues generating code.
cautionWhen working with multiple OpenAPI 2.0 JSON files, identical
basePathvalues across files may cause issues in the generated code: We recommend ensuring that each OpenAPI 2.0 JSON file has a uniquebasePathvalue that matches the actual base path when the service is deployed. -
Unzip the downloaded Extend Codegen CLI template pack, navigate to the extracted folder, and run the
makecommand to generate the code.unzip accelbyte-go-sdk-template-pack.zipcd accelbyte-go-sdk-template-pack/make all \
CODEGEN_IMAGE_VERSION=<codegen-cli-version> \
SDK_PATH=/path/to/my/extend-service-extension-module-sdk \
SPEC_PATH=/path/to/my/extend-service-extension-module-sdk/specinfo- The
CODEGEN_IMAGE_VERSIONcan be found here. For new projects, it is recommended to use the latest available version. - The
PROJECT_PATHandSPEC_PATHcome from step 1.
- The
-
Add
extend-service-extension-module-sdkas a package module togo.modfile in your Go application project.module golang-application
go 1.18
replace (
github.com/AccelByte/accelbyte-go-modular-sdk/guildService-sdk => /path/to/the/extend-service-extension-module-sdk
)
require (
github.com/AccelByte/accelbyte-go-modular-sdk/guildService-sdk v0.0.0-00010101000000-000000000000
github.com/AccelByte/accelbyte-go-modular-sdk/iam-sdk v0.1.0-alpha.1
github.com/AccelByte/accelbyte-go-modular-sdk/services-api v0.1.0-alpha.1
)For an example of how to use a module in the Go Modular Extend SDK, refer to this getting started sample project.