Skip to main content

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

Last updated on March 5, 2025

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, such as those created with the Extend Service Extension.

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.

info

When following this guide, be sure to use the Go Modular Extend SDK instead of the Go Extend SDK.

Prerequisites

  1. 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
      ...
  2. Extend Codegen CLI template pack zip for Go.

  3. A valid OpenAPI 2.0 JSON file for your custom service.

    tip

    In an Extend Service Extension project, you can generate an OpenAPI 2.0 JSON file without running or deploying the service: First, ensure that the base_path property in the service.proto file matches the actual base path when the service is deployed and update it if needed. Then, run make proto in the project folder, and the file will be saved at gateway/apidocs/service.swagger.json.

Generate Go Extend SDK Module for Extend Service Extension

  1. Place the OpenAPI 2.0 JSON file for your custom service in the extend-service-extension-module-sdk/spec folder. In this example, the file is named guild.json.

    /path/to/my/extend-service-extension-module-sdk/
    |__ spec/
    |__ guild.json
    info

    The 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.

    caution

    When working with multiple OpenAPI 2.0 JSON files, identical basePath values across files may cause issues in the generated code: We recommend ensuring that each OpenAPI 2.0 JSON file has a unique basePath value that matches the actual base path when the service is deployed.

  2. Unzip the downloaded Extend Codegen CLI template pack, navigate to the extracted folder, and run the make command to generate the code.

    unzip accelbyte-go-sdk-template-pack.zip
    cd 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/spec
    info
    • The CODEGEN_IMAGE_VERSION can be found here. For new projects, it is recommended to use the latest available version.
    • The PROJECT_PATH and SPEC_PATH come from step 1.
  3. Add extend-service-extension-module-sdk as a package module to go.mod file 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.