Introducing Our New Services SDK Collection, Starting with Golang SDK
Written by our VP of Tech, Raymond Arifianto. Article was originally published on AccelByte Blog. Posted here for more people to observe.
With AccelByte Cloud, we are enabling game studios to focus on building experiences to delight their players, while we take care of the complexity of running the servers 24/7 as a fully managed service.
Using our Unity and UE4 SDKs, game developers call into our API endpoints, and integrate our online features into their games.
But with the recent trend of Games as a Service and Cross-Platform Gaming, we see a need to shift a lot of logic from Game Clients to the Backend. This helps developers create an engaging, fair, and safe experience for all of their players, regardless of which platforms they are playing on.
Here are some examples of logic that can only be run securely on the Backend:
- Real-time dynamic difficulty adjustment based on player behavior
- Custom logic that rewards players based on their engagement with your brand, in and out of the game
- Custom matchmaking logic that groups players based on real life interactions
- Daily login or Seasonal Promo rewards
Previously, there were two ways you could extend AccelByte Cloud’s capabilities:
- For simple computation and logic, you could use Augment (more on this below).
- For complex logic, you could rely on our Custom Engineering team to build new microservices that were tailored to your game’s needs.
And now we’re introducing an exciting third option with the release of our Services SDK collection, starting with our Golang SDK.
What is it for?
It is an SDK that lets you write services that talk to your AccelByte services in a secure, S2S fashion.
When to use Golang SDK:
- You want to integrate your existing backend systems into AccelByte’s platform.
- You want to have full control over server authoritative logic. For example, you are building a service that encapsulates some of your “special sauce” logic, and having it built and iterated by AccelByte Professional Services might not be ideal.
Comparing Augment to the Golang SDK
Augment, our serverless function framework, lets you write functions that enable you to talk to our various services.
| | Augment | Golang SDK |
|--------------------------|------------------------------------------------|---------------------------|
| Hosting | Hosted and managed within AccelByte’s Backend | Hosted and managed by you |
| Can handle complex logic | Limited | Unlimited, you control it |
| Maximum execution time | By default, 1 minute limit | Unlimited, you control it |
| Database | Comes with simple key-value storage | You have full control |
Quick Demonstration
Let’s see the Golang Service SDK in action. In this simple tutorial, we are going to create a simple AWS Lambda function that uses our Golang SDK to interact with our Statistics service on behalf of a user. If you’d like to learn more about our Statistics service, please check out this article.
These are the high level steps that we will implement:
Detailed steps:
- Create a new OAuth Client in the AccelByte Admin Portal that has the right permissions.
From your AccelByte Admin Portal, create a private OAuth Client with a clientID and clientSecret. Since we would like this OAuth client to be able to read and write a Stat Item, make sure to grant it Create and Read permissions to this Admin endpoint
ADMIN:NAMESPACE:{namespace}:USER:*:STATITEM
For more details about AccelByte permission setup, please read our Permissions documentation.
2. Create a new AWS Lambda from the AWS Console. Make sure to set the Lambda Runtime to be Golang 1.x.
In your Golang code, import github.com/AccelByte/accelbyte-go-sdk v0.1.0 in your go.mod.
This is the code snippet:
func main() {
lambda.Start(Handler)
}
func Handler(request *Request) (interface{}, error) {
accessToken := request.AccessToken
tokenResponseV3, err := convertTokenToTokenResponseV3(accessToken)
if err != nil {
return nil, err
}
tokenRepositoryImpl := &TokenRepositoryImpl{}
if tokenResponseV3 != nil {
err = tokenRepositoryImpl.Store(*tokenResponseV3)
if err != nil {
return nil, err
}
}
return createUserStatItem(request.Params, tokenRepositoryImpl)
}
func createUserStatItem(params RequestParams, tokenRepositoryImpl *TokenRepositoryImpl) (interface{}, error) {
statisticService := service.StatisticService{
SocialServiceClient: factory.NewSocialClient(&ConfigRepositoryImpl{}),
TokenRepository: tokenRepositoryImpl,
}
err := statisticService.CreateUserStatItem(params.Namespace, params.UserID, params.StatCode)
if err != nil {
return nil, err
}
return nil, nil
}
Set the environment variable of your Lambda to APP_CLIENT_ID , APP_CLIENT_SECRET with the client ID and secret from the Admin Portal. This allows us to determine the right permissions and scope for the calls.
3. Create an AWS API-Gateway to make a Lambda function so it can be triggered by either a POST or GET HTTP request.
Create a new API, and make sure to set REST as the protocol. Set it to integrate with your Lambda, as seen in the image below:
Deploy your API. You should get an Invoke URL.
4. To test this out, you can use your favorite HTTP client like Postman to make a request to the AWS API-Gateway with these parameters: IAM access token, request body, AWS access key, and AWS secret key.
When you invoke the function, it will update the User Statistics.
Q&A
Will there be more language runtimes supported, like TypeScript, C#, or Java?
Yes! Please reach out to us if you are interested to learn more about the Service SDKs we have in the works.
Learn More
You can find our Golang SDK in our public Github.
Send us a message at hello@accelbyte.io if you have any questions, or if you would like to try our hands-on tutorial.