Use the Gcore Go SDK to make typed REST calls, initialize the client, poll tasks, paginate results, and handle errors and retries.
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
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:
// Uses GCORE_CLOUD_PROJECT_ID and GCORE_CLOUD_REGION_ID read by gcore.NewClient()ctx := context.Background()page, err := client.Cloud.Instances.List(ctx, cloud.InstanceListParams{})if err != nil { panic(err)}for _, inst := range page.Results { fmt.Println(inst.ID, inst.Name)}
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:
params.Name = param.Null[string]()
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:
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:
The client retries connection errors, 408, 409, 429, and 5xx errors twice by default. Requests have no default timeout - use context to set one:
// Set a 5-minute budget for the request including all retriesctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)defer cancel()client.Cloud.Projects.New( ctx, cloud.ProjectNewParams{Name: "my-project"}, option.WithRequestTimeout(20*time.Second), // per-retry timeout)
Disable or configure retries:
// Globallyclient := gcore.NewClient(option.WithMaxRetries(0))// Per requestclient.Cloud.Projects.New(ctx, params, option.WithMaxRetries(5))
Middleware
Apply custom logic to all requests using option.WithMiddleware: