Skip to main content
The gcore-go module provides typed access to the Gcore REST API from Go 1.22+. Generated from the OpenAPI specification using Stainless, request structs use Go’s type system and mark JSON fields with omitzero, which takes effect in Go 1.24 and later. Responses are strongly typed structs with a .JSON metadata field for optional field inspection. Module: github.com/G-Core/gcore-go · Source: gcore-go on GitHub

Install

To pin a version, use a tag from the gcore-go releases.

Initialize the client

gcore.NewClient() returns a value type (gcore.Client), not a pointer. The client reads GCORE_API_KEY, GCORE_CLOUD_PROJECT_ID, and GCORE_CLOUD_REGION_ID from the environment by default:

First call

List all instances in a project and region:

Request parameters

Required primitive fields carry the tag `api:"required"` and are always serialized, even when zero. Optional fields are wrapped in param.Opt[T] and set using the provided constructors:
To send null for an optional field instead of omitting it:
Flavor IDs are region-specific. Run client.Cloud.Instances.Flavors.List(ctx, params) to see what flavors are available in a given region before creating an instance.

Task polling

Cloud API write operations return a task ID. Use NewAndPoll methods where available - they submit the request and block until the resource is ready:
When NewAndPoll is not available for a resource, poll with client.Cloud.Tasks.Poll directly:
task.CreatedResources is a typed struct. Access fields as task.CreatedResources.Instances[0], not as a map. The client.Cloud.Tasks.Get(ctx, taskID) method takes only the task ID string - no project or region parameters.

Pagination

Use ListAutoPaging() to iterate across all pages automatically:
For manual page control:

Error handling

Use errors.As to inspect API errors:

Retries and timeouts

The client retries connection errors, 408, 409, 429, and 5xx errors twice by default. Requests have no default timeout - use context to set one:
Disable or configure retries:

Middleware

Apply custom logic to all requests using option.WithMiddleware:
When multiple middleware functions are provided, they run left to right. Client-level middleware runs before per-request middleware.

Accessing raw response data

Use option.WithResponseInto() to capture the raw HTTP response alongside the parsed result: