Skip to main content

Overview

The Storage service provides two types of cloud storage solutions:
  • S3-Compatible Storage: Object storage with full S3 API compatibility for storing and retrieving files
  • SFTP Storage: Traditional file transfer protocol with password and SSH key authentication
All storage services are accessed through the client.Storage namespace.

Storage Types

S3-Compatible Storage

Provides object storage with S3 API compatibility:
  • Bucket management with lifecycle policies
  • CORS configuration for web applications
  • Public/private access policies
  • Compatible with standard S3 SDKs and tools
  • Automatic credential generation

SFTP Storage

Provides secure file transfer capabilities:
  • Password-based authentication
  • SSH key-based authentication
  • Traditional directory structure
  • Encrypted file transfers

Available Services

The Storage service includes the following sub-services:
ServiceDescription
Storage.BucketsCreate and manage S3 buckets
Storage.Buckets.LifecycleConfigure automatic object expiration
Storage.Buckets.CorsSet up Cross-Origin Resource Sharing
Storage.Buckets.PolicyManage bucket access policies
Storage.CredentialsGenerate and manage storage credentials
Storage.LocationsList available geographic locations
Storage.StatisticsView storage usage statistics

Creating Storage

import (
    "context"
    "github.com/G-Core/gcore-go"
    "github.com/G-Core/gcore-go/storage"
)

client := gcore.NewClient()

params := storage.StorageNewParams{
    Name:     "my-s3-storage",
    Type:     storage.StorageNewParamsTypeS3Compatible,
    Location: "ams",
}

newStorage, err := client.Storage.New(context.Background(), params)
if err != nil {
    // Handle error
}

fmt.Printf("Access Key: %s\n", newStorage.Credentials.S3.AccessKey)
fmt.Printf("Secret Key: %s\n", newStorage.Credentials.S3.SecretKey)

Listing Storage Instances

params := storage.StorageListParams{
    Type:     storage.StorageListParamsTypeS3Compatible,
    Location: param.NewOpt("ams"),
}

storages, err := client.Storage.List(context.Background(), params)
if err != nil {
    // Handle error
}

for _, s := range storages.Results {
    fmt.Printf("Storage: %s (ID: %d)\n", s.Name, s.ID)
}

Getting Storage Details

storageDetails, err := client.Storage.Get(context.Background(), storageID)
if err != nil {
    // Handle error
}

fmt.Printf("Name: %s\n", storageDetails.Name)
fmt.Printf("Address: %s\n", storageDetails.Address)
fmt.Printf("Status: %s\n", storageDetails.ProvisioningStatus)

Updating Storage

params := storage.StorageUpdateParams{
    Expires:     param.NewOpt("30 days"),
    ServerAlias: param.NewOpt("my-custom-domain.com"),
}

updatedStorage, err := client.Storage.Update(context.Background(), storageID, params)
if err != nil {
    // Handle error
}

Deleting Storage

err := client.Storage.Delete(context.Background(), storageID)
if err != nil {
    // Handle error
}

Restoring Deleted Storage

S3 storages can be restored within 2 weeks of deletion:
err := client.Storage.Restore(
    context.Background(),
    storageID,
    storage.StorageRestoreParams{},
)
if err != nil {
    // Handle error
}

Storage Object

id
int64
required
Unique identifier for the storage instance
name
string
required
User-defined name for the storage instance
type
string
required
Storage protocol type: s3_compatible or sftp
location
string
required
Geographic location code where storage is provisioned
address
string
required
Full hostname/address for accessing the storage endpoint
provisioning_status
string
required
Current status: creating, ok, updating, deleting, or deleted
created_at
string
required
ISO 8601 timestamp when the storage was created
credentials
object
can_restore
bool
Whether storage can be restored if deleted (S3 only, within 2 weeks)
expires
string
ISO 8601 timestamp when storage will expire (if set)
server_alias
string
Custom domain alias for accessing the storage

Geographic Locations

Storage can be provisioned in various geographic locations for optimal performance. Available locations include:
  • ams - Amsterdam
  • s-ed1 - Frankfurt
  • s-stage - Staging environment
Use the Storage.Locations service to retrieve the complete list of available locations.

Error Handling

All methods return an error that should be checked:
storage, err := client.Storage.Get(context.Background(), storageID)
if err != nil {
    log.Fatalf("Failed to get storage: %v", err)
}

See Also

Build docs developers (and LLMs) love