Skip to main content

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

Last updated on October 24, 2024

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.

note

In this configuration, you need to use the Go Modular Extend SDK instead of 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. The latest version of the template pack zip for Go.

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

      info

      You can generate Open API 2.0 from the Extend Service Extension app project without running or deploying the app itself. Run make proto inside your Extend Service Extension app project, then get the gateway/apidocs/service.swagger.json spec file.

Generate Go Extend SDK Module for Extend Service Extension

  1. 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 is guild.json.

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

    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 we recommend using all lowercase alphabets (a-z) to avoid issues when generating code.

  2. Unzip the contents of the template pack zip file you downloaded. Then, from the unzipped contents, note the location of the Makefile.

  3. 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
    note
    • 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 and SPEC_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
  4. Add extend-service-extension-module-sdk as a package module into go.mod file in your golang-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
    )
    important

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