エクステンド Codegen CLI を使用してエクステンドサービス拡張用に Go Extend SDK モジュールを生成する
Overview
This article walks you through how to generate a custom service module for Go Modular Extend SDK using Extend Codegen CLI template pack.
A custom service module enables you to use Go Modular Extend SDK to interact with custom service APIs, such as one created using Extend Service Extension.
An Extend Codegen CLI template pack consists of a Makefile
and Jinja
template files. In order to generate code, you need to invoke a single make
command. The make
command runs Extend Codegen CLI with Jinja
template files and a given OpenAPI 2.0 JSON file that describes the custom service APIs to generate code.
In this configuration, you need to use the Go Modular Extend SDK instead of 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
docker
group: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
...
The latest version of the template pack zip for Go.
A valid OpenAPI 2.0 JSON file of your custom service.
For example, you can see the service.swagger.json, which is generated automatically when created using the Extend Service Extension.
備考You can generate Open API 2.0 from the Extend Service Extension app template without running or deploying the app itself. Run
make proto
inside your Extend Service Extension app template, then get thegateway/apidocs/service.swagger.json
spec file.
Generate Go Extend SDK Module for Extend Service Extension
Get a valid OpenAPI 2.0 JSON file of your custom service and place it in under
extend-service-extension-module-sdk/spec
folder. In this example, it isguild.json
..
└── /path/to/my/extend-service-extension-module-sdk/
└── spec
└── guild.jsonimportantThe 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 when generating code.
Unzip the contents of the template pack zip file you downloaded. Then, from the unzipped contents, note the location of the
Makefile
.In a terminal, go to the location of the
Makefile
and execute the following command: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/spec注記- Get the AccelByte
codegen-cli-version
from the Docker Hub. For new projects, we recommend to start with the latest available version. - The
SDK_PATH
andSPEC_PATH
comes from step 1.
The result should look like the following.
.
└── /path/to/my/extend-service-extension-module-sdk/
├── docs
│ └── operations
│ └── guild.md
├── guild-sdk
│ ├── go.mod
│ ├── go.sum
│ └── pkg
│ ├── client_factory.go
│ ├── guildclient
│ │ ├── guild_service
│ │ │ ├── guild_service_client.go
│ │ │ ├── guild_service_create_or_update_guild_progress_parameters.go
│ │ │ ├── guild_service_create_or_update_guild_progress_responses.go
│ │ │ ├── guild_service_get_guild_progress_parameters.go
│ │ │ └── guild_service_get_guild_progress_responses.go
│ │ └── justice_guild_service_client.go
│ ├── guildclientmodels
│ │ ├── guild_create_or_update_guild_progress_response.go
│ │ ├── guild_get_guild_progress_response.go
│ │ ├── guild_guild_progress.go
│ │ ├── protobuf_any.go
│ │ └── rpc_status.go
│ ├── version.go
│ ├── version.txt
│ └── wrapper_guildService.go
├── samples
│ └── cli
│ ├── cmd
│ │ └── guild
│ │ ├── guild.go
│ │ └── guildService
│ │ ├── guildServiceCreateOrUpdateGuildProgress.go
│ │ └── guildServiceGetGuildProgress.go
│ └── tests
│ └── guild-cli-test.sh
└── spec
└── guild.json- Get the AccelByte
Add
extend-service-extension-module-sdk
as a package module intogo.mod
file in yourgolang-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
)importantYou need to use Go Modular Extend SDK in your
golang-application
project instead of Go Extend SDK.For an example on how to use a module with Go Modular Extend SDK, refer to the AccelByte Go Modular Extend SDK Getting started guide.