Golang SDK Getting Started Guide
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
- Create a Game Namespace if you don't have one yet. Be sure to keep the namespace's Namespace ID as you will need it later.
- Create an OAuth Client with a Confidential client type. Keep the Client ID and the Client Secret somewhere safe as you will be using them in this tutorial.
- Download the AccelByte Golang SDK.
Additional Resources
- Download the Sample App for the AccelByte Golang SDK.
- Refer to the AccelByte Golang SDK Index to find information about the included services' wrappers.
Tutorials
Install the AccelByte Golang SDK
To install the AccelByte Golang SDK into your project directory, follow these steps:
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
Then run this command in the Terminal.
$ go mod tidy
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:
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")
}
Initialize the service SDK.
oauthService := service.OauthService{
IamService: factory.NewIamClient(&repository.ConfigRepositoryImpl{}),
ConfigRepository: &repository.ConfigRepositoryImpl{},
TokenRepository: &repository.TokenRepositoryImpl{},
}Call the GrantTokenCredentials wrapper.
err := oauthService.GrantTokenCredentials("", "")
if err != nil {
return err
}
return nilThis 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.
Legal
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.
Related Concepts
- Once you've set up the Cloud Golang SDK, start building your first matchmaking app using AWS SAM.