Skip to main content

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

Last updated on May 15, 2024
info

Extend is in Open Beta for AGS Premium Clients! This means that the Extend add-on is available for you to try in your development environment. You can submit your feedback via our Extend Open Beta feedback form.

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.

    • 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 sample app without running or deploying the app itself. Run make proto inside your Extend Service Extension sample app, 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
    important

    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.