Prerequisites
Before you begin, make sure you have:- Go 1.22 or higher installed
- A Gcore account with an API key
- The Gcore Go SDK installed (see Installation)
Complete Example
Here’s a complete working example that creates a new Cloud project:main.go
Step-by-Step Walkthrough
Let’s break down the example above into steps:Import required packages
Import the Gcore SDK and related packages you’ll need:
gcore- Main SDK packagecloud- Cloud services (projects, instances, volumes, etc.)option- Request options for configuring the client and requests
Create a client instance
Initialize the Gcore client with your API key:Using environment variables (recommended):
If you don’t provide an API key, the client will automatically look for the
GCORE_API_KEY environment variable. This is the recommended approach for production applications.Make your first API call
Use the client to create a new Cloud project:The SDK uses the standard Go
context package for request lifecycle management. Use context.TODO() for simple examples, or pass a more specific context for production code.Running Your Code
Save the code to a file (e.g.,main.go) and run it:
Error Handling
The SDK returns detailed error information when requests fail. Here’s how to handle errors properly:Common Operations
Here are a few more examples of common operations:List Resources
Using Context for Timeouts
Configuring Request Options
Next Steps
Now that you’ve made your first API call, explore more features:Authentication
Learn about different authentication methods
Core Concepts
Understand pagination, error handling, and more
Cloud Services
Explore Cloud resources like instances and volumes
API Reference
Browse the complete API documentation
