Developer-friendly & type-safe Go SDK specifically catered to leverage github.com/hathora/cloud-sdk-go API.
Important
This SDK is not yet ready for production use. To complete setup please follow the steps outlined in your workspace. Delete this section before > publishing to a package manager.
Hathora Cloud API: Welcome to the Hathora Cloud API documentation! Learn how to use the Hathora Cloud APIs to build and scale your game servers globally.
To add the SDK as a dependency to your project:
go get hathoracloud
package main
import (
"context"
"hathoracloud"
"log"
)
func main() {
ctx := context.Background()
s := hathoracloud.New(
hathoracloud.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
hathoracloud.WithOrgID("org-6f706e83-0ec1-437a-9a46-7d4281eb2f39"),
hathoracloud.WithAppID("app-af469a92-5b45-4565-b3c4-b79878de67d2"),
)
res, err := s.TokensV1.GetOrgTokens(ctx, "org-6f706e83-0ec1-437a-9a46-7d4281eb2f39")
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
This SDK supports the following security scheme globally:
Name | Type | Scheme |
---|---|---|
HathoraDevToken |
http | HTTP Bearer |
You can configure it using the WithSecurity
option when initializing the SDK client instance. For example:
package main
import (
"context"
"hathoracloud"
"log"
)
func main() {
ctx := context.Background()
s := hathoracloud.New(
hathoracloud.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
hathoracloud.WithOrgID("org-6f706e83-0ec1-437a-9a46-7d4281eb2f39"),
hathoracloud.WithAppID("app-af469a92-5b45-4565-b3c4-b79878de67d2"),
)
res, err := s.TokensV1.GetOrgTokens(ctx, "org-6f706e83-0ec1-437a-9a46-7d4281eb2f39")
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
Some operations in this SDK require the security scheme to be specified at the request level. For example:
package main
import (
"context"
"hathoracloud"
"hathoracloud/models/components"
"hathoracloud/models/operations"
"log"
)
func main() {
ctx := context.Background()
s := hathoracloud.New(
hathoracloud.WithOrgID("org-6f706e83-0ec1-437a-9a46-7d4281eb2f39"),
hathoracloud.WithAppID("app-af469a92-5b45-4565-b3c4-b79878de67d2"),
)
res, err := s.LobbiesV3.CreateLobby(ctx, operations.CreateLobbySecurity{
PlayerAuth: "<YOUR_BEARER_TOKEN_HERE>",
}, components.CreateLobbyV3Params{
Visibility: components.LobbyVisibilityPrivate,
RoomConfig: hathoracloud.String("{\"name\":\"my-room\"}"),
Region: components.RegionSeattle,
}, hathoracloud.String("app-af469a92-5b45-4565-b3c4-b79878de67d2"), hathoracloud.String("LFG4"), hathoracloud.String("2swovpy1fnunu"))
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
Available methods
GetAppsV1Deprecated- GetAppsV1Deprecated⚠️ DeprecatedCreateAppV1Deprecated- CreateAppV1Deprecated⚠️ DeprecatedUpdateAppV1Deprecated- UpdateAppV1Deprecated⚠️ DeprecatedGetAppInfoV1Deprecated- GetAppInfoV1Deprecated⚠️ DeprecatedDeleteAppV1Deprecated- DeleteAppV1Deprecated⚠️ Deprecated
- LoginAnonymous - LoginAnonymous
- LoginNickname - LoginNickname
- LoginGoogle - LoginGoogle
- GetBalance - GetBalance
- GetUpcomingInvoiceItems - GetUpcomingInvoiceItems
- GetUpcomingInvoiceTotal - GetUpcomingInvoiceTotal
- GetPaymentMethod - GetPaymentMethod
- InitStripeCustomerPortalURL - InitStripeCustomerPortalUrl
- GetInvoices - GetInvoices
GetBuildsDeprecated- GetBuildsDeprecated⚠️ DeprecatedGetBuildInfoDeprecated- GetBuildInfoDeprecated⚠️ DeprecatedCreateBuildDeprecated- CreateBuildDeprecated⚠️ DeprecatedDeleteBuildDeprecated- DeleteBuildDeprecated⚠️ DeprecatedRunBuildDeprecated- RunBuildDeprecated⚠️ Deprecated
GetBuildsV2Deprecated- GetBuildsV2Deprecated⚠️ DeprecatedGetBuildInfoV2Deprecated- GetBuildInfoV2Deprecated⚠️ DeprecatedCreateBuildV2Deprecated- CreateBuildV2Deprecated⚠️ DeprecatedCreateBuildWithUploadURLV2Deprecated- CreateBuildWithUploadUrlV2Deprecated⚠️ DeprecatedCreateWithMultipartUploadsV2Deprecated- CreateWithMultipartUploadsV2Deprecated⚠️ DeprecatedDeleteBuildV2Deprecated- DeleteBuildV2Deprecated⚠️ DeprecatedRunBuildV2Deprecated- RunBuildV2Deprecated⚠️ Deprecated
- GetBuilds - GetBuilds
- CreateBuild - CreateBuild
- GetBuild - GetBuild
- DeleteBuild - DeleteBuild
- RunBuild - RunBuild
GetDeploymentsV1Deprecated- GetDeploymentsV1Deprecated⚠️ DeprecatedGetLatestDeploymentV1Deprecated- GetLatestDeploymentV1Deprecated⚠️ DeprecatedGetDeploymentInfoV1Deprecated- GetDeploymentInfoV1Deprecated⚠️ DeprecatedCreateDeploymentV1Deprecated- CreateDeploymentV1Deprecated⚠️ Deprecated
GetDeploymentsV2Deprecated- GetDeploymentsV2Deprecated⚠️ DeprecatedGetLatestDeploymentV2Deprecated- GetLatestDeploymentV2Deprecated⚠️ DeprecatedGetDeploymentInfoV2Deprecated- GetDeploymentInfoV2Deprecated⚠️ DeprecatedCreateDeploymentV2Deprecated- CreateDeploymentV2Deprecated⚠️ Deprecated
- GetDeployments - GetDeployments
- CreateDeployment - CreateDeployment
- GetLatestDeployment - GetLatestDeployment
- GetDeployment - GetDeployment
GetPingServiceEndpointsDeprecated- GetPingServiceEndpointsDeprecated⚠️ Deprecated
- GetPingServiceEndpoints - GetPingServiceEndpoints
- GetFleets - GetFleets
- GetFleetRegion - GetFleetRegion
- UpdateFleetRegion - UpdateFleetRegion
- GetFleetMetrics - GetFleetMetrics
CreatePrivateLobbyDeprecated- CreatePrivateLobbyDeprecated⚠️ DeprecatedCreatePublicLobbyDeprecated- CreatePublicLobbyDeprecated⚠️ DeprecatedListActivePublicLobbiesDeprecatedV1- ListActivePublicLobbiesDeprecatedV1⚠️ Deprecated
CreatePrivateLobby- CreatePrivateLobby⚠️ DeprecatedCreatePublicLobby- CreatePublicLobby⚠️ DeprecatedCreateLocalLobby- CreateLocalLobby⚠️ DeprecatedCreateLobbyDeprecated- CreateLobbyDeprecated⚠️ DeprecatedListActivePublicLobbiesDeprecatedV2- ListActivePublicLobbiesDeprecatedV2⚠️ DeprecatedGetLobbyInfo- GetLobbyInfo⚠️ DeprecatedSetLobbyState- SetLobbyState⚠️ Deprecated
- CreateLobby - CreateLobby
- ListActivePublicLobbies - ListActivePublicLobbies
- GetLobbyInfoByRoomID - GetLobbyInfoByRoomId
- GetLobbyInfoByShortCode - GetLobbyInfoByShortCode
- GetLogsForProcess - GetLogsForProcess
- DownloadLogForProcess - DownloadLogForProcess
- SendVerificationEmail - SendVerificationEmail
GetMetricsDeprecated- GetMetricsDeprecated⚠️ Deprecated
- GetOrgs - GetOrgs
- GetUserPendingInvites - GetUserPendingInvites
- GetOrgMembers - GetOrgMembers
- InviteUser - InviteUser
- UpdateUserInvite - UpdateUserInvite
- RescindInvite - RescindInvite
- GetOrgPendingInvites - GetOrgPendingInvites
- AcceptInvite - AcceptInvite
- RejectInvite - RejectInvite
- GetUsageLimits - GetUsageLimits
GetRunningProcesses- GetRunningProcesses⚠️ DeprecatedGetStoppedProcesses- GetStoppedProcesses⚠️ DeprecatedGetProcessInfoDeprecated- GetProcessInfoDeprecated⚠️ Deprecated
GetProcessInfoV2Deprecated- GetProcessInfoV2Deprecated⚠️ DeprecatedGetLatestProcessesV2Deprecated- GetLatestProcessesV2Deprecated⚠️ DeprecatedGetProcessesCountExperimentalV2Deprecated- GetProcessesCountExperimentalV2Deprecated⚠️ DeprecatedStopProcessV2Deprecated- StopProcessV2Deprecated⚠️ DeprecatedCreateProcessV2Deprecated- CreateProcessV2Deprecated⚠️ Deprecated
- GetLatestProcesses - GetLatestProcesses
- GetProcessesCountExperimental - GetProcessesCountExperimental
- CreateProcess - CreateProcess
- GetProcess - GetProcess
- StopProcess - StopProcess
- GetProcessMetrics - GetProcessMetrics
CreateRoomDeprecated- CreateRoomDeprecated⚠️ DeprecatedGetRoomInfoDeprecated- GetRoomInfoDeprecated⚠️ DeprecatedGetActiveRoomsForProcessDeprecated- GetActiveRoomsForProcessDeprecated⚠️ DeprecatedGetInactiveRoomsForProcessDeprecated- GetInactiveRoomsForProcessDeprecated⚠️ DeprecatedDestroyRoomDeprecated- DestroyRoomDeprecated⚠️ DeprecatedSuspendRoomDeprecated- SuspendRoomDeprecated⚠️ DeprecatedGetConnectionInfoDeprecated- GetConnectionInfoDeprecated⚠️ Deprecated
- CreateRoom - CreateRoom
- GetRoomInfo - GetRoomInfo
- GetActiveRoomsForProcess - GetActiveRoomsForProcess
- GetInactiveRoomsForProcess - GetInactiveRoomsForProcess
- DestroyRoom - DestroyRoom
SuspendRoomV2Deprecated- SuspendRoomV2Deprecated⚠️ Deprecated- GetConnectionInfo - GetConnectionInfo
- UpdateRoomConfig - UpdateRoomConfig
- GetOrgTokens - GetOrgTokens
- CreateOrgToken - CreateOrgToken
- RevokeOrgToken - RevokeOrgToken
Certain parameters are configured globally. These parameters may be set on the SDK client instance itself during initialization. When configured as an option during SDK initialization, These global values will be used as defaults on the operations that use them. When such operations are called, there is a place in each to override the global value, if needed.
For example, you can set orgId
to "org-6f706e83-0ec1-437a-9a46-7d4281eb2f39"
at SDK initialization and then you do not have to pass the same value on calls to operations like GetOrgTokens
. But if you want to do so you may, which will locally override the global setting. See the example code below for a demonstration.
The following global parameters are available.
Name | Type | Description |
---|---|---|
OrgID | string | The OrgID parameter. |
AppID | string | The AppID parameter. |
package main
import (
"context"
"hathoracloud"
"log"
)
func main() {
ctx := context.Background()
s := hathoracloud.New(
hathoracloud.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
hathoracloud.WithOrgID("org-6f706e83-0ec1-437a-9a46-7d4281eb2f39"),
hathoracloud.WithAppID("app-af469a92-5b45-4565-b3c4-b79878de67d2"),
)
res, err := s.TokensV1.GetOrgTokens(ctx, "org-6f706e83-0ec1-437a-9a46-7d4281eb2f39")
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
To change the default retry strategy for a single API call, simply provide a retry.Config
object to the call by using the WithRetries
option:
package main
import (
"context"
"hathoracloud"
"hathoracloud/retry"
"log"
"models/operations"
)
func main() {
ctx := context.Background()
s := hathoracloud.New(
hathoracloud.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
hathoracloud.WithOrgID("org-6f706e83-0ec1-437a-9a46-7d4281eb2f39"),
hathoracloud.WithAppID("app-af469a92-5b45-4565-b3c4-b79878de67d2"),
)
res, err := s.TokensV1.GetOrgTokens(ctx, "org-6f706e83-0ec1-437a-9a46-7d4281eb2f39", operations.WithRetries(
retry.Config{
Strategy: "backoff",
Backoff: &retry.BackoffStrategy{
InitialInterval: 1,
MaxInterval: 50,
Exponent: 1.1,
MaxElapsedTime: 100,
},
RetryConnectionErrors: false,
}))
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
If you'd like to override the default retry strategy for all operations that support retries, you can use the WithRetryConfig
option at SDK initialization:
package main
import (
"context"
"hathoracloud"
"hathoracloud/retry"
"log"
)
func main() {
ctx := context.Background()
s := hathoracloud.New(
hathoracloud.WithRetryConfig(
retry.Config{
Strategy: "backoff",
Backoff: &retry.BackoffStrategy{
InitialInterval: 1,
MaxInterval: 50,
Exponent: 1.1,
MaxElapsedTime: 100,
},
RetryConnectionErrors: false,
}),
hathoracloud.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
hathoracloud.WithOrgID("org-6f706e83-0ec1-437a-9a46-7d4281eb2f39"),
hathoracloud.WithAppID("app-af469a92-5b45-4565-b3c4-b79878de67d2"),
)
res, err := s.TokensV1.GetOrgTokens(ctx, "org-6f706e83-0ec1-437a-9a46-7d4281eb2f39")
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
Handling errors in this SDK should largely match your expectations. All operations return a response object or an error, they will never return both.
By Default, an API error will return errors.SDKError
. When custom error responses are specified for an operation, the SDK may also return their associated error. You can refer to respective Errors tables in SDK docs for more details on possible error types for each operation.
For example, the GetOrgTokens
function may return the following errors:
Error Type | Status Code | Content Type |
---|---|---|
errors.APIError | 401, 404, 429 | application/json |
errors.SDKError | 4XX, 5XX | */* |
package main
import (
"context"
"errors"
"hathoracloud"
"hathoracloud/models/errors"
"log"
)
func main() {
ctx := context.Background()
s := hathoracloud.New(
hathoracloud.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
hathoracloud.WithOrgID("org-6f706e83-0ec1-437a-9a46-7d4281eb2f39"),
hathoracloud.WithAppID("app-af469a92-5b45-4565-b3c4-b79878de67d2"),
)
res, err := s.TokensV1.GetOrgTokens(ctx, "org-6f706e83-0ec1-437a-9a46-7d4281eb2f39")
if err != nil {
var e *errors.APIError
if errors.As(err, &e) {
// handle error
log.Fatal(e.Error())
}
var e *errors.SDKError
if errors.As(err, &e) {
// handle error
log.Fatal(e.Error())
}
}
}
You can override the default server globally using the WithServerIndex(serverIndex int)
option when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:
# | Server |
---|---|
0 | https://api.hathora.dev |
1 | https:/// |
package main
import (
"context"
"hathoracloud"
"log"
)
func main() {
ctx := context.Background()
s := hathoracloud.New(
hathoracloud.WithServerIndex(1),
hathoracloud.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
hathoracloud.WithOrgID("org-6f706e83-0ec1-437a-9a46-7d4281eb2f39"),
hathoracloud.WithAppID("app-af469a92-5b45-4565-b3c4-b79878de67d2"),
)
res, err := s.TokensV1.GetOrgTokens(ctx, "org-6f706e83-0ec1-437a-9a46-7d4281eb2f39")
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
The default server can also be overridden globally using the WithServerURL(serverURL string)
option when initializing the SDK client instance. For example:
package main
import (
"context"
"hathoracloud"
"log"
)
func main() {
ctx := context.Background()
s := hathoracloud.New(
hathoracloud.WithServerURL("https://api.hathora.dev"),
hathoracloud.WithSecurity("<YOUR_BEARER_TOKEN_HERE>"),
hathoracloud.WithOrgID("org-6f706e83-0ec1-437a-9a46-7d4281eb2f39"),
hathoracloud.WithAppID("app-af469a92-5b45-4565-b3c4-b79878de67d2"),
)
res, err := s.TokensV1.GetOrgTokens(ctx, "org-6f706e83-0ec1-437a-9a46-7d4281eb2f39")
if err != nil {
log.Fatal(err)
}
if res != nil {
// handle response
}
}
The Go SDK makes API calls that wrap an internal HTTP client. The requirements for the HTTP client are very simple. It must match this interface:
type HTTPClient interface {
Do(req *http.Request) (*http.Response, error)
}
The built-in net/http
client satisfies this interface and a default client based on the built-in is provided by default. To replace this default with a client of your own, you can implement this interface yourself or provide your own client configured as desired. Here's a simple example, which adds a client with a 30 second timeout.
import (
"net/http"
"time"
"github.com/myorg/your-go-sdk"
)
var (
httpClient = &http.Client{Timeout: 30 * time.Second}
sdkClient = sdk.New(sdk.WithClient(httpClient))
)
This can be a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration.
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation. We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.