メインコンテンツまでスキップ

Use Extend Codegen CLI to generate Go Extend SDK Module for Extend Service Extension

Last updated on November 14, 2023
note

Customization is not available on the AccelByte Gaming Services (AGS) Starter tier yet. It's coming soon!

Overview

The Extend Codegen CLI is a tool for generating code from an OpenAPI 2.0 JSON file according to the template pack used with it. The OpenAPI 2.0 JSON file may come from a custom service, such as Extend Service Extension. The template pack consists of Jinja templates and a Makefile to invoke Extend Codegen CLI and the Jinja templates for generating code.

This particular template pack is used to generate a custom service module for the Go Modular Extend SDK. It will allow developers to interact with their custom service APIs more effectively by using Go Modular Extend SDK, which offers enhanced functionality, such as login capabilities, token refresh, token validation, and HTTP request retries. All of these features are included to enable developers to concentrate on their specific objectives.

important

Go Modular Extend SDK is not to be confused with Go Extend SDK. For this you need to use Go Modular Extend SDK instead of Go Extend SDK.

Prerequisites

  1. Based on your operating system, you will need the following tools:

    a. Linux Ubuntu 20.04 (or Windows 10 WSL2)

     i. bash

    ii. make

    iii. Docker v23.x

    b. Windows 10

     i. [Cygwin](https://github.com/AccelByte/extend-codegen-cli/blob/master/windows/INSTALLING_CYGWIN.md)

    ii. Docker v23.x
    備考

    Support for macOS may be available soon.

  2. The latest version of the Extend Codegen CLI binary for your OS. For Linux, you may have to use chmod +x accelbyte-codegen-linux_amd64 to allow the file to be executed.

    備考

    Some examples demonstrate the use of the accelbyte-codegen executable file, with the filename potentially varying in your specific scenario such as accelbyte-codegen-linux_amd64 or accelbyte-codegen-windows_amd64, depending on your operating system.

  3. The latest version of the template pack zip.

  4. A valid Open API 2.0 JSON file from your custom service.

Generate Go Extend SDK Module for Extend Service Extension

  1. Copy a valid Open API 2.0 JSON file from your custom service into extend-service-extension-module-sdk folder. For this example, use the GuildService.swagger.json file and copy it to /path/to/my/extend-service-extension-module-sdk/spec/ folder as guild.json.

    .
    └── /path/to/my/extend-service-extension-module-sdk/
    └── spec
    └── guild.json
    危険

    The 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 please use all lowercase alphabets (a-z) to avoid issues when generating code. :::

  2. Unzip the contents of the template pack zip file you downloaded. Next, navigate inside the folder where a Makefile file is located and execute the following command.

    make all \
    CODEGEN_PATH=/path/to/the/accelbyte-codegen \
    SDK_PATH=/path/to/my/extend-service-extension-module-sdk \
    SPEC_PATH=/path/to/my/extend-service-extension-module-sdk/spec
    注記

    The SDK_PATH and SPEC_PATH comes from step 1.

    The output folder structure may look like below.

    .
    └── /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
  3. Add extend-service-extension-module-sdk as a package module into your golang-application project's go.mod file.

    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
    )
    important

    You must be using Go Modular Extend SDK in your golang-application project instead of the old Go Extend SDK.

    For an example on how to use a module in Go Modular Extend SDK, see here.