# README
github.com/hathora/ci/internal/sdk
š Welcome to your new SDK! š
It has been generated successfully based on your OpenAPI spec. However, it is not yet ready for production use. Here are some next steps:
- š Make your SDK feel handcrafted by customizing it
- ā»ļø Refine your SDK quickly by iterating locally with the Speakeasy CLI
- š Publish your SDK to package managers by configuring automatic publishing
- ⨠When ready to productionize, delete this section from the README
SDK Installation
go get github.com/hathora/ci/internal/sdk
SDK Example Usage
Example
package main
import (
"context"
"github.com/hathora/ci/internal/sdk"
"github.com/hathora/ci/internal/sdk/models/shared"
"log"
"os"
)
func main() {
s := sdk.New(
sdk.WithSecurity(shared.Security{
HathoraDevToken: sdk.String(os.Getenv("HATHORA_DEV_TOKEN")),
}),
sdk.WithAppID("app-af469a92-5b45-4565-b3c4-b79878de67d2"),
)
var orgID string = "org-6f706e83-0ec1-437a-9a46-7d4281eb2f39"
ctx := context.Background()
res, err := s.TokensV1.GetOrgTokens(ctx, orgID)
if err != nil {
log.Fatal(err)
}
if res.ListOrgTokens != nil {
// handle response
}
}
Available Resources and Operations
TokensV1
- GetOrgTokens - List all organization tokens for a given org.
- CreateOrgToken - Create a new organization token.
- RevokeOrgToken - Revoke an organization token.
RoomsV1
CreateRoomDeprecated- :warning: DeprecatedGetRoomInfoDeprecated- :warning: DeprecatedGetActiveRoomsForProcessDeprecated- :warning: DeprecatedGetInactiveRoomsForProcessDeprecated- :warning: DeprecatedDestroyRoomDeprecated- :warning: DeprecatedSuspendRoomDeprecated- :warning: DeprecatedGetConnectionInfoDeprecated- :warning: Deprecated
RoomsV2
- CreateRoom - Create a new room for an existing application. Poll the
GetConnectionInfo()
endpoint to get connection details for an active room. - GetRoomInfo - Retreive current and historical allocation data for a room.
- GetActiveRoomsForProcess - Get all active rooms for a given process.
- GetInactiveRoomsForProcess - Get all inactive rooms for a given process.
- DestroyRoom - Destroy a room. All associated metadata is deleted.
SuspendRoomV2Deprecated- Suspend a room. The room is unallocated from the process but can be rescheduled later using the sameroomId
. :warning: Deprecated- GetConnectionInfo - Poll this endpoint to get connection details to a room. Clients can call this endpoint without authentication.
- UpdateRoomConfig
ProcessesV1
GetRunningProcesses- Retrieve 10 most recently started process objects for an application. Filter the array by optionally passing in aregion
. :warning: DeprecatedGetStoppedProcesses- Retrieve 10 most recently stopped process objects for an application. Filter the array by optionally passing in aregion
. :warning: DeprecatedGetProcessInfoDeprecated- Get details for a process. :warning: Deprecated
ProcessesV2
- GetProcessInfoV2Deprecated - Get details for a process.
- GetLatestProcessesV2Deprecated - Retrieve the 10 most recent processes objects for an application. Filter the array by optionally passing in a
status
orregion
. - GetProcessesCountExperimentalV2Deprecated - Count the number of processes objects for an application. Filter by optionally passing in a
status
orregion
. - StopProcessV2Deprecated - Stops a process immediately.
- CreateProcessV2Deprecated - Creates a process without a room. Use this to pre-allocate processes ahead of time so that subsequent room assignment via CreateRoom() can be instant.
ProcessesV3
- GetLatestProcesses - Retrieve the 10 most recent processes objects for an application. Filter the array by optionally passing in a
status
orregion
. - GetProcessesCountExperimental - Count the number of processes objects for an application. Filter by optionally passing in a
status
orregion
. - CreateProcess - Creates a process without a room. Use this to pre-allocate processes ahead of time so that subsequent room assignment via CreateRoom() can be instant.
- GetProcess - Get details for a process.
- StopProcess - Stops a process immediately.
OrganizationsV1
- GetOrgs - Returns an unsorted list of all organizations that you are a member of (an accepted membership invite). An organization is uniquely identified by an
orgId
. - GetUserPendingInvites
- GetOrgMembers
- InviteUser
- RescindInvite
- GetOrgPendingInvites
- AcceptInvite
- RejectInvite
MetricsV1
- GetMetrics - Get metrics for a process using
appId
andprocessId
.
ManagementV1
LogsV1
GetLogsForApp- Returns a stream of logs for an application usingappId
. :warning: Deprecated- GetLogsForProcess - Returns a stream of logs for a process using
appId
andprocessId
. - DownloadLogForProcess - Download entire log file for a stopped process.
GetLogsForDeployment- Returns a stream of logs for a deployment usingappId
anddeploymentId
. :warning: Deprecated
LobbiesV1
CreatePrivateLobbyDeprecated- :warning: DeprecatedCreatePublicLobbyDeprecated- :warning: DeprecatedListActivePublicLobbiesDeprecatedV1- :warning: Deprecated
LobbiesV2
CreatePrivateLobby- :warning: DeprecatedCreatePublicLobby- :warning: DeprecatedCreateLocalLobby- :warning: DeprecatedCreateLobbyDeprecated- Create a new lobby for an application. A lobby object is a wrapper around a room object. With a lobby, you get additional functionality like configuring the visibility of the room, managing the state of a match, and retrieving a list of public lobbies to display to players. :warning: DeprecatedListActivePublicLobbiesDeprecatedV2- Get all active lobbies for a an application. Filter by optionally passing in aregion
. Use this endpoint to display all public lobbies that a player can join in the game client. :warning: DeprecatedGetLobbyInfo- Get details for a lobby. :warning: DeprecatedSetLobbyState- Set the state of a lobby. State is intended to be set by the server and must be smaller than 1MB. Use this endpoint to store match data like live player count to enforce max number of clients or persist end-game data (i.e. winner or final scores). :warning: Deprecated
LobbiesV3
- CreateLobby - Create a new lobby for an application. A lobby object is a wrapper around a room object. With a lobby, you get additional functionality like configuring the visibility of the room, managing the state of a match, and retrieving a list of public lobbies to display to players.
- ListActivePublicLobbies - Get all active lobbies for a given application. Filter the array by optionally passing in a
region
. Use this endpoint to display all public lobbies that a player can join in the game client. - GetLobbyInfoByRoomID - Get details for a lobby.
- GetLobbyInfoByShortCode - Get details for a lobby. If 2 or more lobbies have the same
shortCode
, then the most recently created lobby will be returned.
DiscoveryV1
GetPingServiceEndpointsDeprecated- Returns an array of V1 regions with a host and port that a client can directly ping. Open a websocket connection towss://<host>:<port>/ws
and send a packet. To calculate ping, measure the time it takes to get an echo packet back. :warning: Deprecated
DiscoveryV2
- GetPingServiceEndpoints - Returns an array of all regions with a host and port that a client can directly ping. Open a websocket connection to
wss://<host>:<port>/ws
and send a packet. To calculate ping, measure the time it takes to get an echo packet back.
DeploymentsV1
GetDeploymentsV1Deprecated- Returns an array of deployments for an application. :warning: DeprecatedGetLatestDeploymentV1Deprecated- Get the latest deployment for an application. :warning: DeprecatedGetDeploymentInfoV1Deprecated- Get details for a deployment. :warning: DeprecatedCreateDeploymentV1Deprecated- Create a new deployment. Creating a new deployment means all new rooms created will use the latest deployment configuration, but existing games in progress will not be affected. :warning: Deprecated
DeploymentsV2
- GetDeploymentsV2Deprecated - Returns an array of deployments for an application.
- GetLatestDeploymentV2Deprecated - Get the latest deployment for an application.
- GetDeploymentInfoV2Deprecated - Get details for a deployment.
- CreateDeploymentV2Deprecated - Create a new deployment. Creating a new deployment means all new rooms created will use the latest deployment configuration, but existing games in progress will not be affected.
DeploymentsV3
- GetDeployments - Returns an array of deployments for an application.
- CreateDeployment - Create a new deployment. Creating a new deployment means all new rooms created will use the latest deployment configuration, but existing games in progress will not be affected.
- GetLatestDeployment - Get the latest deployment for an application.
- GetDeployment - Get details for a deployment.
BuildsV1
GetBuildsDeprecated- Returns an array of builds for an application. :warning: DeprecatedGetBuildInfoDeprecated- Get details for a build. :warning: DeprecatedCreateBuildDeprecated- Creates a new build. Responds with abuildId
that you must pass toRunBuild()
to build the game server artifact. You can optionally pass in abuildTag
to associate an external version with a build. :warning: DeprecatedDeleteBuildDeprecated- Delete a build. All associated metadata is deleted. :warning: DeprecatedRunBuildDeprecated- Builds a game server artifact from a tarball you provide. Pass in thebuildId
generated fromCreateBuild()
. :warning: Deprecated
BuildsV2
- GetBuildsV2Deprecated - Returns an array of builds for an application.
- GetBuildInfoV2Deprecated - Get details for a build.
- CreateBuildV2Deprecated - Creates a new build. Responds with a
buildId
that you must pass toRunBuild()
to build the game server artifact. You can optionally pass in abuildTag
to associate an external version with a build. - CreateBuildWithUploadURLV2Deprecated - Creates a new build with
uploadUrl
that can be used to upload the build to before callingrunBuild
. Responds with abuildId
that you must pass toRunBuild()
to build the game server artifact. You can optionally pass in abuildTag
to associate an external version with a build. - CreateWithMultipartUploadsV2Deprecated - Creates a new build with optional
multipartUploadUrls
that can be used to upload larger builds in parts before callingrunBuild
. Responds with abuildId
that you must pass toRunBuild()
to build the game server artifact. You can optionally pass in abuildTag
to associate an external version with a build. - DeleteBuildV2Deprecated - Delete a build. All associated metadata is deleted.
- RunBuildV2Deprecated - Builds a game server artifact from a tarball you provide. Pass in the
buildId
generated fromCreateBuild()
.
BuildsV3
- GetBuilds - Returns an array of builds for an application.
- CreateBuild - Creates a new build with optional
multipartUploadUrls
that can be used to upload larger builds in parts before callingrunBuild
. Responds with abuildId
that you must pass toRunBuild()
to build the game server artifact. You can optionally pass in abuildTag
to associate an external version with a build. - GetBuild - Get details for a build.
- DeleteBuild - Delete a build. All associated metadata is deleted. Be careful which builds you delete. This endpoint does not prevent you from deleting actively used builds. Deleting a build that is actively build used by an app's deployment will cause failures when creating rooms.
- RunBuild - Builds a game server artifact from a tarball you provide. Pass in the
buildId
generated fromCreateBuild()
.
BillingV1
- GetBalance
- GetUpcomingInvoiceItems
- GetUpcomingInvoiceTotal
- GetPaymentMethod
- InitStripeCustomerPortalURL
- GetInvoices
AuthV1
- LoginAnonymous - Returns a unique player token for an anonymous user.
- LoginNickname - Returns a unique player token with a specified nickname for a user.
- LoginGoogle - Returns a unique player token using a Google-signed OIDC
idToken
.
AppsV1
- GetAppsV1Deprecated - Returns an unsorted list of your organizationās applications. An application is uniquely identified by an
appId
. - CreateAppV1Deprecated - Create a new application.
- UpdateAppV1Deprecated - Update data for an existing application using
appId
. - GetAppInfoV1Deprecated - Get details for an application using
appId
. - DeleteAppV1Deprecated - Delete an application using
appId
. Your organization will lose access to this application.
AppsV2
- GetApps - Returns an unsorted list of your organizationās applications. An application is uniquely identified by an
appId
. - CreateApp - Create a new application.
- UpdateApp - Update data for an existing application using
appId
. - GetApp - Get details for an application using
appId
. - DeleteApp - Delete an application using
appId
. Your organization will lose access to this application.
Global Parameters
A parameter is configured globally. This parameter may be set on the SDK client instance itself during initialization. When configured as an option during SDK initialization, This global value will be used as the default on the operations that use it. When such operations are called, there is a place in each to override the global value, if needed.
For example, you can set appId
to "app-af469a92-5b45-4565-b3c4-b79878de67d2"
at SDK initialization and then you do not have to pass the same value on calls to operations like CreateRoomDeprecated
. But if you want to do so you may, which will locally override the global setting. See the example code below for a demonstration.
Available Globals
The following global parameter is available.
Name | Type | Required | Description |
---|---|---|---|
AppID | string | The AppID parameter. |
Example
package main
import (
"context"
"github.com/hathora/ci/internal/sdk"
"github.com/hathora/ci/internal/sdk/models/shared"
"log"
"os"
)
func main() {
s := sdk.New(
sdk.WithSecurity(shared.Security{
HathoraDevToken: sdk.String(os.Getenv("HATHORA_DEV_TOKEN")),
}),
sdk.WithAppID("app-af469a92-5b45-4565-b3c4-b79878de67d2"),
)
createRoomParams := shared.CreateRoomParams{
RoomConfig: sdk.String("{\"name\":\"my-room\"}"),
Region: shared.RegionChicago,
}
var appID *string = sdk.String("app-af469a92-5b45-4565-b3c4-b79878de67d2")
var roomID *string = sdk.String("2swovpy1fnunu")
ctx := context.Background()
res, err := s.RoomsV1.CreateRoomDeprecated(ctx, createRoomParams, appID, roomID)
if err != nil {
log.Fatal(err)
}
if res.RoomID != nil {
// handle response
}
}
Error Handling
Handling errors in this SDK should largely match your expectations. All operations return a response object or an error, they will never return both. When specified by the OpenAPI spec document, the SDK will return the appropriate subclass.
Error Object | Status Code | Content Type |
---|---|---|
sdkerrors.APIError | 401,404,429 | application/json |
sdkerrors.SDKError | 4xx-5xx | / |
Example
package main
import (
"context"
"errors"
"github.com/hathora/ci/internal/sdk"
"github.com/hathora/ci/internal/sdk/models/sdkerrors"
"github.com/hathora/ci/internal/sdk/models/shared"
"log"
"os"
)
func main() {
s := sdk.New(
sdk.WithSecurity(shared.Security{
HathoraDevToken: sdk.String(os.Getenv("HATHORA_DEV_TOKEN")),
}),
sdk.WithAppID("app-af469a92-5b45-4565-b3c4-b79878de67d2"),
)
var orgID string = "org-6f706e83-0ec1-437a-9a46-7d4281eb2f39"
ctx := context.Background()
res, err := s.TokensV1.GetOrgTokens(ctx, orgID)
if err != nil {
var e *sdkerrors.APIError
if errors.As(err, &e) {
// handle error
log.Fatal(e.Error())
}
var e *sdkerrors.SDKError
if errors.As(err, &e) {
// handle error
log.Fatal(e.Error())
}
}
}
Server Selection
Select Server by Index
You can override the default server globally using the WithServerIndex
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 | Variables |
---|---|---|
0 | https://api.hathora.dev | None |
1 | https:/// | None |
Example
package main
import (
"context"
"github.com/hathora/ci/internal/sdk"
"github.com/hathora/ci/internal/sdk/models/shared"
"log"
"os"
)
func main() {
s := sdk.New(
sdk.WithServerIndex(1),
sdk.WithSecurity(shared.Security{
HathoraDevToken: sdk.String(os.Getenv("HATHORA_DEV_TOKEN")),
}),
sdk.WithAppID("app-af469a92-5b45-4565-b3c4-b79878de67d2"),
)
var orgID string = "org-6f706e83-0ec1-437a-9a46-7d4281eb2f39"
ctx := context.Background()
res, err := s.TokensV1.GetOrgTokens(ctx, orgID)
if err != nil {
log.Fatal(err)
}
if res.ListOrgTokens != nil {
// handle response
}
}
Override Server URL Per-Client
The default server can also be overridden globally using the WithServerURL
option when initializing the SDK client instance. For example:
package main
import (
"context"
"github.com/hathora/ci/internal/sdk"
"github.com/hathora/ci/internal/sdk/models/shared"
"log"
"os"
)
func main() {
s := sdk.New(
sdk.WithServerURL("https://api.hathora.dev"),
sdk.WithSecurity(shared.Security{
HathoraDevToken: sdk.String(os.Getenv("HATHORA_DEV_TOKEN")),
}),
sdk.WithAppID("app-af469a92-5b45-4565-b3c4-b79878de67d2"),
)
var orgID string = "org-6f706e83-0ec1-437a-9a46-7d4281eb2f39"
ctx := context.Background()
res, err := s.TokensV1.GetOrgTokens(ctx, orgID)
if err != nil {
log.Fatal(err)
}
if res.ListOrgTokens != nil {
// handle response
}
}
Custom HTTP Client
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.
Authentication
Per-Client Security Schemes
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"
"github.com/hathora/ci/internal/sdk"
"github.com/hathora/ci/internal/sdk/models/shared"
"log"
"os"
)
func main() {
s := sdk.New(
sdk.WithSecurity(shared.Security{
HathoraDevToken: sdk.String(os.Getenv("HATHORA_DEV_TOKEN")),
}),
sdk.WithAppID("app-af469a92-5b45-4565-b3c4-b79878de67d2"),
)
var orgID string = "org-6f706e83-0ec1-437a-9a46-7d4281eb2f39"
ctx := context.Background()
res, err := s.TokensV1.GetOrgTokens(ctx, orgID)
if err != nil {
log.Fatal(err)
}
if res.ListOrgTokens != nil {
// handle response
}
}
Per-Operation Security Schemes
Some operations in this SDK require the security scheme to be specified at the request level. For example:
package main
import (
"context"
"github.com/hathora/ci/internal/sdk"
"github.com/hathora/ci/internal/sdk/models/operations"
"github.com/hathora/ci/internal/sdk/models/shared"
"log"
"os"
)
func main() {
s := sdk.New(
sdk.WithAppID("app-af469a92-5b45-4565-b3c4-b79878de67d2"),
)
security := operations.CreatePrivateLobbyDeprecatedSecurity{
PlayerAuth: os.Getenv("PLAYER_AUTH"),
}
var appID *string = sdk.String("app-af469a92-5b45-4565-b3c4-b79878de67d2")
var region *shared.Region = shared.RegionLondon.ToPointer()
var local *bool = sdk.Bool(false)
ctx := context.Background()
res, err := s.LobbiesV1.CreatePrivateLobbyDeprecated(ctx, security, appID, region, local)
if err != nil {
log.Fatal(err)
}
if res.RoomID != nil {
// handle response
}
}
Special Types
Retries
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"
"github.com/hathora/ci/internal/sdk"
"github.com/hathora/ci/internal/sdk/models/shared"
"github.com/hathora/ci/internal/sdk/retry"
"log"
"models/operations"
"os"
)
func main() {
s := sdk.New(
sdk.WithSecurity(shared.Security{
HathoraDevToken: sdk.String(os.Getenv("HATHORA_DEV_TOKEN")),
}),
sdk.WithAppID("app-af469a92-5b45-4565-b3c4-b79878de67d2"),
)
var orgID string = "org-6f706e83-0ec1-437a-9a46-7d4281eb2f39"
ctx := context.Background()
res, err := s.TokensV1.GetOrgTokens(ctx, orgID, 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.ListOrgTokens != 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"
"github.com/hathora/ci/internal/sdk"
"github.com/hathora/ci/internal/sdk/models/shared"
"github.com/hathora/ci/internal/sdk/retry"
"log"
"os"
)
func main() {
s := sdk.New(
sdk.WithRetryConfig(
retry.Config{
Strategy: "backoff",
Backoff: &retry.BackoffStrategy{
InitialInterval: 1,
MaxInterval: 50,
Exponent: 1.1,
MaxElapsedTime: 100,
},
RetryConnectionErrors: false,
}),
sdk.WithSecurity(shared.Security{
HathoraDevToken: sdk.String(os.Getenv("HATHORA_DEV_TOKEN")),
}),
sdk.WithAppID("app-af469a92-5b45-4565-b3c4-b79878de67d2"),
)
var orgID string = "org-6f706e83-0ec1-437a-9a46-7d4281eb2f39"
ctx := context.Background()
res, err := s.TokensV1.GetOrgTokens(ctx, orgID)
if err != nil {
log.Fatal(err)
}
if res.ListOrgTokens != nil {
// handle response
}
}
Development
Maturity
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.
Contributions
While we value open-source contributions to this SDK, this library is generated programmatically. Feel free to open a PR or a Github issue as a proof of concept and we'll do our best to include it in a future release!