The gcore-go module provides typed access to the full Gcore REST API from Go 1.22+. Generated from the OpenAPI specification using Stainless, all request structs use Go’s type system with omitzero semantics from Go 1.24 encoding/json. All 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
Requirements
Go 1.22 or higher.
Install
To pin a specific version:
Initialize the client
gcore.NewClient() returns a value type (gcore.Client), not a pointer. The client reads the API key from the GCORE_API_KEY environment variable 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.
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: