Skip to main content

Golang SDK Getting Started Guide

Last updated on

Overview

You can use AccelByte Cloud's Golang SDK to implement our backend services within your game. The SDK acts as a bridge between your game and our services. Follow the tutorials below to learn how to set up our Cloud Golang SDK.

Prerequisites

Additional Resources

Tutorials

Install the AccelByte Golang SDK

To install the AccelByte Golang SDK into your project directory, follow these steps:

  1. Import the AccelByte Golang SDK into the go.mod file directly from the GitHub repository by running the following command in the terminal. Make sure to use the latest version of our Golang SDK.

    go get github.com/AccelByte/accelbyte-go-sdk
  2. Then run this command in the Terminal.

    $ go mod tidy
  3. Open the go.mod file and it will look like this.

    module aws-lambda-functions

    go 1.16

    require (
    github.com/AccelByte/accelbyte-go-sdk latest
    )

Log in as a Client using the SDK

To log in as the client you created earlier, follow these steps:

  1. Create empty structs for TokenRepositoryImpl and ConfigRepositoryImpl that will be used for the following actions:

    • The TokenRepositoryImpl struct is used to store, get, and remove tokens.

      type TokenRepositoryImpl struct {}

      func (t *TokenRepositoryImpl) Store(accessToken iamclientmodels.OauthmodelTokenResponseV3) error {
      clientTokenV3 = accessToken
      return nil
      }

      func (t *TokenRepositoryImpl) GetToken() (*iamclientmodels.OauthmodelTokenResponseV3, error) {
      return &clientTokenV3, nil
      }

      func (t *TokenRepositoryImpl) RemoveToken() error {
      return nil
      }
    • The TokenRepositoryImpl struct to get the Client ID and Client Secret.

      type ConfigRepositoryImpl struct {}

      func (c *ConfigRepositoryImpl) GetClientId() string {
      return os.Getenv("APP_CLIENT_ID")
      }

      func (c *ConfigRepositoryImpl) GetClientSecret() string {
      return os.Getenv("APP_CLIENT_SECRET")
      }

      func (c *ConfigRepositoryImpl) GetJusticeBaseUrl() string {
      return os.Getenv("ACCELBYTE_BASE_URL")
      }
  2. Initialize the service SDK.

    oauthService := service.OauthService{
    IamService: factory.NewIamClient(&repository.ConfigRepositoryImpl{}),
    ConfigRepository: &repository.ConfigRepositoryImpl{},
    TokenRepository: &repository.TokenRepositoryImpl{},
    }
  3. Call the GrantTokenCredentials wrapper.

    err := oauthService.GrantTokenCredentials("", "")
    if err != nil {
    return err
    }

    return nil

    This wrapper provides a straightforward way to retrieve client credentials.

    param := &o_auth2_0.TokenGrantV3Params{
    Code: &code,
    CodeVerifier: &codeVerifier,
    GrantType: "client_credentials",
    }

    accessToken, _, _, _, err :=
    oauthService.IamService.OAuth20.TokenGrantV3(param, client.BasicAuth(clientId, clientSecret))
    if err != nil {
    return err
    }

    return nil

Import AccelByte Services

Now you're ready to integrate any of the following AccelByte services into your application. All services have already been imported in .../pkg/service. The <your-service> will be changed to the service name you want to use automatically during the import. or in the service folder inside the accelbyte-go-sdk repository.

SDK Examples

See our Golang SDK example repo for a selection of test cases you can use to customize your game.

IAM

import (
"github.com/AccelByte/accelbyte-go-sdk/iam-sdk/pkg/iamclientmodels"
)

Basic

import (
"github.com/AccelByte/accelbyte-go-sdk/basic-sdk/pkg/basicclientmodels"
)

Social

import (
"github.com/AccelByte/accelbyte-go-sdk/social-sdk/pkg/socialclientmodels"
)

Platform

import (
"github.com/AccelByte/accelbyte-go-sdk/platform-sdk/pkg/platformclientmodels"
)

Group

import (
"github.com/AccelByte/accelbyte-go-sdk/group-sdk/pkg/groupclientmodels"
)

Cloud Save

import (
"github.com/AccelByte/accelbyte-go-sdk/cloudsave-sdk/pkg/cloudsaveclientmodels"
)

DSM Controller

import (
"github.com/AccelByte/accelbyte-go-sdk/dsmc-sdk/pkg/dsmcclientmodels"
)

Session Browser

import (
"github.com/AccelByte/accelbyte-go-sdk/sessionbrowser-sdk/pkg/sessionbrowserclientmodels"
)

Lobby

import (
"github.com/AccelByte/accelbyte-go-sdk/lobby-sdk/pkg/lobbyclientmodels"
)

Achievement

import (
"github.com/AccelByte/accelbyte-go-sdk/achievement-sdk/pkg/achievementclientmodels"
)

See the Achievement documentation to learn how to connect custom services to Achievement service using the Golang server-side SDK.

DS Log Manager

import (
"github.com/AccelByte/accelbyte-go-sdk/dslogmanager-sdk/pkg/dslogmanagerclientmodels"
)

See the DS Log Manager documentation to learn how to connect custom services to DS Log Manager service using the Golang server-side SDK.

UGC

import (
"github.com/AccelByte/accelbyte-go-sdk/ugc-sdk/pkg/ugcclientmodels"
)

See the UGC documentation to learn how to connect custom services to UGC service using the Golang server-side SDK.

Leaderboard

import (
"github.com/AccelByte/accelbyte-go-sdk/leaderboard-sdk/pkg/leaderboardclientmodels"
)

See the Leaderboard documentation to learn how to connect custom services to Leaderboard service using the Golang server-side SDK.

GDPR

import (
"github.com/AccelByte/accelbyte-go-sdk/gdpr-sdk/pkg/gdprclientmodels"
)

See the GDPR documentation to learn how to connect custom services to GDPR service using the Golang server-side SDK.

import (
"github.com/AccelByte/accelbyte-go-sdk/legal-sdk/pkg/legalclientmodels"
)

See the Legal documentation to learn how to connect custom services to Legal service using the Golang server-side SDK.

Matchmaking

import (
"github.com/AccelByte/accelbyte-go-sdk/matchmaking-sdk/pkg/matchmakingclientmodels"
)

See our Cloud Matchmaking documentation to learn how to connect custom services to Matchmaking service using the Golang server-side SDK.

  • Once you've set up the Cloud Golang SDK, start building your first matchmaking app using AWS SAM.