Projects are organizational units that group cloud resources for access control and billing. Each client can have multiple projects, with one designated as the default project.
Methods
New
Create a new project.
func (r *ProjectService) New(ctx context.Context, body ProjectNewParams, opts ...option.RequestOption) (*Project, error)
Automatically generated project ID
Whether this is the default project
Deletion timestamp (if deleted)
Update
Update project name or description.
func (r *ProjectService) Update(ctx context.Context, params ProjectUpdateParams, opts ...option.RequestOption) (*Project, error)
List
List all projects with optional filtering.
func (r *ProjectService) List(ctx context.Context, query ProjectListParams, opts ...option.RequestOption) (*pagination.OffsetPage[Project], error)
func (r *ProjectService) ListAutoPaging(ctx context.Context, query ProjectListParams, opts ...option.RequestOption) *pagination.OffsetPageAutoPager[Project]
Filter by client ID (admin only)
Include deleted projects in results
Sort order: created_at.asc, created_at.desc, name.asc, name.desc
Maximum number of results per page
Number of results to skip
Get
Retrieve a specific project by ID.
func (r *ProjectService) Get(ctx context.Context, query ProjectGetParams, opts ...option.RequestOption) (*Project, error)
Delete
Delete a project and all associated resources.
func (r *ProjectService) Delete(ctx context.Context, body ProjectDeleteParams, opts ...option.RequestOption) (*TaskIDList, error)
func (r *ProjectService) DeleteAndPoll(ctx context.Context, body ProjectDeleteParams, opts ...option.RequestOption) error
This operation is irreversible and will delete all cloud resources in all regions. Default projects cannot be deleted.
Examples
Create a Project
import (
"context"
"github.com/G-Core/gcore-go"
"github.com/G-Core/gcore-go/cloud"
)
client := gcore.NewClient()
project, err := client.Cloud.Projects.New(context.Background(), cloud.ProjectNewParams{
Name: "my-production-project",
Description: gcore.String("Production environment resources"),
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Created project ID: %d\n", project.ID)
List All Projects
projects, err := client.Cloud.Projects.List(context.Background(), cloud.ProjectListParams{})
if err != nil {
log.Fatal(err)
}
for _, project := range projects.Results {
fmt.Printf("Project: %s (ID: %d)\n", project.Name, project.ID)
}
List Projects with Auto-Paging
iter := client.Cloud.Projects.ListAutoPaging(context.Background(),
cloud.ProjectListParams{
Limit: gcore.Int(10),
},
)
for iter.Next() {
project := iter.Current()
fmt.Printf("Project: %s\n", project.Name)
}
if err := iter.Err(); err != nil {
log.Fatal(err)
}
Update a Project
project, err := client.Cloud.Projects.Update(context.Background(),
cloud.ProjectUpdateParams{
ProjectID: gcore.Int(projectID),
Name: gcore.String("updated-name"),
Description: gcore.String("Updated description"),
},
)
Get Project Details
project, err := client.Cloud.Projects.Get(context.Background(),
cloud.ProjectGetParams{
ProjectID: gcore.Int(projectID),
},
)
Delete a Project
// Delete and wait for completion
err := client.Cloud.Projects.DeleteAndPoll(context.Background(),
cloud.ProjectDeleteParams{
ProjectID: gcore.Int(projectID),
},
)
if err != nil {
log.Fatal(err)
}
Common Use Cases
Organizing Resources by Environment
Create separate projects for different environments:
envs := []string{"development", "staging", "production"}
for _, env := range envs {
project, err := client.Cloud.Projects.New(context.Background(),
cloud.ProjectNewParams{
Name: fmt.Sprintf("myapp-%s", env),
Description: gcore.String(fmt.Sprintf("%s environment", env)),
},
)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Created %s project: %d\n", env, project.ID)
}
Finding Projects by Name
projects, err := client.Cloud.Projects.List(context.Background(),
cloud.ProjectListParams{
Name: gcore.String("production"),
},
)