{"id":29572684,"url":"https://github.com/accelbyte/accelbyte-go-sdk","last_synced_at":"2026-01-16T06:22:25.257Z","repository":{"id":37268389,"uuid":"386559634","full_name":"AccelByte/accelbyte-go-sdk","owner":"AccelByte","description":"Golang Extend SDK generated from AccelByte Gaming Services OpenAPI specification","archived":false,"fork":false,"pushed_at":"2025-07-09T06:51:19.000Z","size":187787,"stargazers_count":10,"open_issues_count":0,"forks_count":6,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-07-09T21:58:32.548Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AccelByte.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-07-16T08:06:02.000Z","updated_at":"2025-07-08T23:42:07.000Z","dependencies_parsed_at":"2024-04-18T00:34:27.498Z","dependency_job_id":"b0479627-19d5-47ef-95c5-4f2fa54d3045","html_url":"https://github.com/AccelByte/accelbyte-go-sdk","commit_stats":null,"previous_names":[],"tags_count":106,"template":false,"template_full_name":null,"purl":"pkg:github/AccelByte/accelbyte-go-sdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AccelByte%2Faccelbyte-go-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AccelByte%2Faccelbyte-go-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AccelByte%2Faccelbyte-go-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AccelByte%2Faccelbyte-go-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AccelByte","download_url":"https://codeload.github.com/AccelByte/accelbyte-go-sdk/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AccelByte%2Faccelbyte-go-sdk/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265892512,"owners_count":23845034,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-07-19T05:10:52.546Z","updated_at":"2026-01-16T06:22:25.214Z","avatar_url":"https://github.com/AccelByte.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AccelByte Go SDK\n\nA software development kit (SDK) for interacting with AccelByte services written in Golang.\n\nThis SDK was generated from OpenAPI specification documents included in the [spec](spec) directory.\n\n## Setup\n\nThis SDK requires `go 1.18` or newer version to be installed.\n\n### Import SDK Project\n\nAdd the following to your project's `go.mod`:\n\n```go\nrequire (\n    github.com/AccelByte/accelbyte-go-sdk {VERSION}\n)\n```\n\nReplace `{VERSION}` with a specific release version tag. When starting a new project, \nusing the latest release version is recommended.\n\n### Environment Variables\n\nThe following environment variables need to be set when using `ConfigRepository`.\n\n| Name               | Required                                               | Example                          |\n|--------------------|--------------------------------------------------------|----------------------------------|\n| `AB_BASE_URL`      | Yes                                                    | https://test.accelbyte.io        |\n| `AB_CLIENT_ID`     | Yes                                                    | abcdef0123456789abcdef0123456789 |\n| `AB_CLIENT_SECRET` | Yes, but only if you use a confidential `AB_CLIENT_ID` | ab#c,d)ef(ab#c,d)ef(ab#c,d)ef(ab |\n\n## Usage\n\n### Instantiation\n\n```go\n// example for OAuth20 in IAM service\noAuth20Service := iam.OAuth20Service{\n    Client:           factory.NewIamClient(auth.DefaultConfigRepositoryImpl()), \n    ConfigRepository: auth.DefaultConfigRepositoryImpl(), \n    TokenRepository:  auth.DefaultTokenRepositoryImpl(),\n}\n```\n\n## Enable HTTP Logging\nTo enable http logging feature, set `ENABLE_LOG` to true in the environment variables.\n```\nexport ENABLE_LOG=true\n```\n\n#### With Custom HTTP retry in the client\n\nUse this to get SDK instance with HTTP retry functionality.\n\n```go\ninput := \u0026o_auth2_0.TokenGrantV3Params{\n\t\tPassword:  \u0026password,\n\t\tUsername:  \u0026username,\n\t\tGrantType: o_auth2_0.TokenGrantV3PasswordConstant,\n\t}\ninput.RetryPolicy = \u0026utils.Retry{\n    Transport: OAuth20Service.Client.Runtime.Transport,\n    MaxTries:  utils.MaxTries,\n    Backoff:   utils.NewConstantBackoff(0),\n    RetryCodes: map[int]bool{\n        502: true, // add an error code for bad gateway\n    },\n}\nok, err := OAuth20Service.TokenGrantV3Short(input) // call the wrapper\n```\n\n#### Automatic Token Refresh\n\nThe Automatic Token Refresh is invoked by `auth.RefreshTokenScheduler` inside the `login` wrapper with the Default configuration and can be override.\nUse the following to get SDK instance with automatic token refresh functionality which is performed before each HTTP request but only if access token is almost expired.\n\n```go\noAuth20Service = \u0026iam.OAuth20Service{\n\t\tClient:           factory.NewIamClient(auth.DefaultConfigRepositoryImpl()),\n\t\tConfigRepository: auth.DefaultConfigRepositoryImpl(),\n\t\tTokenRepository:  auth.DefaultTokenRepositoryImpl(),\n\t\tRefreshTokenRepository: \u0026auth.RefreshTokenImpl{ // override the default refresh token. For example, enable the AutoRefresh functionality or change RefreshRate\n                    RefreshRate: 0.5, // refresh when 50% of the token’s lifetime remains.\n                    AutoRefresh: true, // automatically refresh the token in the background.\n\t}\n```\nIf no need to customize the behavior, use the default refresh token configuration.\nThe default RefreshRate is `0.8`, which means the SDK will refresh the token when 20% of its lifetime remains.\n```go\noAuth20Service = \u0026iam.OAuth20Service{\n\t\t...\n\t\tRefreshTokenRepository: auth.DefaultRefreshTokenImpl(), // use the default value\n\t}\n```\nUse the `repository` to access all functions for refresh token.\n\n#### On-demand Refresh Token\n\nThe on-demand refresh token is intended to be used in environment where automatic refresh token cannot work properly e.g. AWS Lambda. The way to initialize it\nis similar to automatic refresh token except the `AutoRefresh` parameter must be set to `false`. After that, `LoginOrRefreshClient` or `LoginOrRefresh` for logging in using client token or username and password respectively can be used before calling any endpoints. These two functions are helper functions for developers to either login or refresh as required.\n\n```go\noAuth20Service = \u0026iam.OAuth20Service{\n    Client:           factory.NewIamClient(auth.DefaultConfigRepositoryImpl()),\n    ConfigRepository: auth.DefaultConfigRepositoryImpl(),\n    TokenRepository:  auth.DefaultTokenRepositoryImpl(),\n    RefreshTokenRepository: \u0026auth.RefreshTokenImpl{\n        RefreshRate: 0.5,\n        AutoRefresh: false, // must be set to false for on demand refresh token\n    },\n}\n...\nerr := oauth.LoginOrRefreshClient(\"clientId\", \"clientSecret\")   // use before calling endpoints, using client token\n...\nerr := oauth.LoginOrRefresh(\"username\", \"password\")     // use before calling endpoints, using username and password\n```\n\n#### Local Token Validation\nLocal token validation is available since version 0.37.0. \nTo enable it, import the package\n```go\nimport (\n    ...\n    \"github.com/AccelByte/accelbyte-go-sdk/services-api/pkg/service/iam\"\n    ...\n)\n```\n- if the boolean `SetLocalValidation` is `true`, it will validate locally.\n- if the boolean `SetLocalValidation` is `false`, it will validate remotely (call `VerifyTokenV3` endpoint).\n```\noAuth20Service.SetLocalValidation(true)\n\nerr = tokenValidator.Validate(accessToken, \u0026requiredPermission, \u0026namespace, nil)\n```\n\n## Login\n\n### Login Using Username and Password\n\n```go\nerr := oAuth20Service.Login(username, password)\nif err != nil {\n    return err\n}\n```\n\nYou can also specify the scope you want for `LoginWithScope(...)`. With the `scope` parameter typed as `string`. By default the scope used is `commerce account social publishing analytics` (a space separated value string).\n\n```go\nerr := oAuth20Service.LoginWithScope(username, password, scope)\nif err != nil {\n    return err\n}\n```\n\n### Login Using OAuth Client (Public or Private)\n\n```go\nerr := oAuth20Service.LoginClient(clientId, clientSecret)\nif err != nil {\n    return err\n}\n```\n\nIt’s possible to pass a context created or derived from another method into LoginClientWithContext(ctx, ...), allowing you to carry tracing information or other context-related data through the login process.\n\n```go\nctx := context.Background()\n\nerr := oAuth20Service.LoginClientWihContext(ctx, clientId, clientSecret)\nif err != nil {\n    return err\n}\n```\n\n:bulb: The use of a Public OAuth Client is highly discouraged! Please ensure that you both set the Client ID and Client Secret.\n\n:bulb: There are other `WithContext` variants of the `LoginX` functions in case you want to use a specific context.\n\n## Parse Access Token\nFunctionality to parse the access token is available in `v0.50.0`.\nThe function exist alongside the Login functionality in `OAuth20Service`. To use it, import the package\n```go\nimport (\n    ...\n    \"github.com/AccelByte/accelbyte-go-sdk/services-api/pkg/service/iam\"\n    ...\n)\n```\nGet the token, and use `ParseAccessToken` function. Set the second parameter as `true` if it wants to validate before parse the access token\n```go\n// get the access token string\naccessToken, err := oAuth20Service.GetToken()\nif err != nil {\n    // fail here\n}\n\n// parse the token\nparsedToken, err := oAuth20Service.ParseAccessToken(accessToken, true) // set true here to validate before parse the access token\nif err != nil {\n    // fail here\n}\n```\n- if the boolean `SetLocalValidation` is `true`, it will validate locally.\n- if the boolean `SetLocalValidation` is `false`, it will validate remotely (call `VerifyTokenV3` endpoint).\n- if the boolean `ParseAccessToken` is `false`, it will not validate the token at all.\n```go\noAuth20Service.SetLocalValidation(true) // call this also to activate local validation whether locally or remotely\n\n// parse the token\nparsedToken, err := oAuth20Service.ParseAccessToken(accessToken, true) // set true here to validate before parsing the access token\nif err != nil {\n// fail here\n}\n```\n\n### Interacting with AccelByte Gaming Services HTTP Endpoints\n\nAs an example, we will get current user profile info using [getMyProfileInfo](https://docs.accelbyte.io/api-explorer/#Basic/getMyProfileInfo) endpoint available in [basic](https://docs.accelbyte.io/api-explorer/#Basic) service.\n\n```go\n// Instantiate UserProfile (Basic service) and input model as the global variable\nvar (\n    userProfileService = \u0026basic.UserProfileService{\n        Client:          factory.NewBasicClient(auth.DefaultConfigRepositoryImpl()), \n        TokenRepository: auth.DefaultTokenRepositoryImpl(),\n    }\n    input = \u0026user_profile.GetUserProfileInfoParams{\n        Namespace: namespace,\n    }\n)\n\n// Login using username and password\nerr := oAuth20Service.Login(username, password)\nif err != nil {\n    return err\n}\n\n// Make a call to getMyProfileInfo endpoint through the wrapper\nok, err := userProfileService.GetMyProfileInfoShort(input)\nif err != nil {\n    return err\n}\n```\nThe `basic-sdk` contains 2 directories:\n- `basicclient` contains the logic to make requests.\n- `basicclientmodels` contains the models such as request and response models.\n\nClient must create a struct that implement following interface:\n\n- `ConfigRepository` is responsible to store configuration.\n- `TokenRepository` is responsible to store access token.\n\nFor more details, see [repository](samples/cli/pkg/repository) for the interface and [cli samples](samples/cli/cmd) on how to use it.\n\n### Interacting with AccelByte Gaming Services WebSocket Endpoints\n\nTo interact with AccelByte Gaming Services services which use WebSocket endpoints e.g. AccelByte Gaming Services Lobby\nService, use an existing Initialisation code or implement custom `connectionutils/ConnectionManager` interface.\n`ConnectionManager` manages WebSocket connection that save, get and close the WebSocket connection. In other words,\nclient should maintain WebSocket connection using `ConnectionManager`.\n\n```go\nconnMgr = \u0026integration.ConnectionManagerImpl{}\nconn, err := connectionutils.NewWSConnection(\noAuth20Service.ConfigRepository, oAuth20Service.TokenRepository,\nconnectionutils.WithEnableAutoReconnect(), connectionutils.WithMessageHandler(lobbyMessageHandler), // do optionals\n)\nif err != nil {\n// error\n}\nlobbyClient := connectionutils.NewLobbyWebSocketClient(conn)\n\n// [optional] do something before Connecting\n\nsuccess, err := lobbyClient.Connect(false) // Connecting\nif err != nil {\n// error\n}\n\nconnMgr.Save(conn)\n\n// CASE Lobby get a notification\nerr = notificationService.GetNotificationMessage()\n// error\n```\n\nFor reference, see [connectionutils_test.go](services-api/pkg/utils/connectionutils/connectionutils_test.go)\nor [samples/cli/pkg/utils/connectionManager.go](samples/cli/pkg/utils/connectionManager.go).\n\n### Refresh Token\n```go\ngetToken, errGetToken := oAuth20Service.TokenRepository.GetToken()\n    if errGetToken != nil {\n        // failed to get token\n    }\n\t\nhasExpired := repository.HasTokenExpired(*getToken) // use the repository of the sdk to get the available functions\n```\n\n## Logout\n```go\nerr := oAuth20Service.Logout()\nif err != nil {\n    return err\n}\n```\n\n## FlightID\nSince v0.64, Go Extend SDK enable support for FlightID transmission during Http request. By default, new flight id will be generated when the sdk is loaded. There will be some case that this default value need to be updated with new value.\n-   To update default flight id globally, use following code:\n    ```go\n    utils.GetDefaultFlightID().SetFlightID(\"\u003cnew flight id value\u003e\");\n    ```\n    This will update the default flight id, and will be used by newly created sdk object (this example use \"userProfileService\").\n    \n    or\n\n    ```go\n    userProfileService.FlightIdRepository = \u0026utils.FlightIdContainer{Value: \"\u003cnew flight id value\u003e\"}\n    ```\n    This will update the default flight id, and will be used by newly created sdk object (won't affect existing sdk object created before this code get executed).\n-   To update flight id value in sdk object, use following code:\n    ```go\n    userProfileService.UpdateFlightId(\"\u003cnew flight id value\u003e\")\n    ```\n    This will update the flight id value stored inside the sdk object. Will be used for all operations executed by the sdk object.\n-   To update flight id value for specific operation, use `UpdateFlightId` parameter when building the operation object.\n    ```go\n    // Make a call to GetMyProfileInfo endpoint\n    input := \u0026user_profile.GetMyProfileInfoParams{\n\t    Namespace: admin,\n    }\n    input.XFlightId = \"\u003cnew flight id value\u003e\"\n    ok, err := userProfileService.GetMyProfileInfoShort(input)\n    ```\n\n## Samples\n\nSample apps are available in the [samples](samples) directory.\n\n## Documentation\n\nReference about AccelByte service endpoints and their corresponding SDK API is available in [docs/operations](docs/operations) directory.\n\nSample app documentations are available in the [docs/samples](docs/samples/) directory.\n\nFor more information on how to use AccelByte services and SDKs, see [docs.accelbyte.io](https://docs.accelbyte.io/).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faccelbyte%2Faccelbyte-go-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faccelbyte%2Faccelbyte-go-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faccelbyte%2Faccelbyte-go-sdk/lists"}