Last Updated: 6/15/2022, 1:51:10 AM

# Golang SDK Getting Started Guide

# Overview

You can use the AccelByte 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 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 (opens new window) 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.<your-service> will be changed to the service name you want to use automatically during the import.

# SDK Examples

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

IAM

API Docs (opens new window)

SDK Reference (opens new window)

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

API Docs (opens new window)

SDK reference (opens new window)

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

API Docs (opens new window)

SDK reference (opens new window)

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

API Docs (opens new window)

SDK reference (opens new window)

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

API Docs (opens new window)

SDK reference (opens new window)

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

API Docs (opens new window)

SDK reference (opens new window)

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

API Docs (opens new window)

SDK reference (opens new window)

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

API Docs (opens new window)

SDK reference (opens new window)

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

API Docs (opens new window)

SDK reference (opens new window)

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

API Docs (opens new window)

SDK reference (opens new window)

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

API Docs (opens new window)

SDK reference (opens new window)

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

API Docs (opens new window)

SDK reference (opens new window)

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

API Docs (opens new window)

SDK reference (opens new window)

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

API Docs (opens new window)

SDK reference (opens new window)

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

API Docs (opens new window)

SDK reference (opens new window)

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

API Docs (opens new window)

SDK reference (opens new window)

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