Path: blob/main/components/public-api/go/examples/workspaces_example.go
2500 views
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package examples56import (7"context"8"fmt"9"os"1011"github.com/bufbuild/connect-go"12"github.com/gitpod-io/gitpod/components/public-api/go/client"13v1 "github.com/gitpod-io/gitpod/components/public-api/go/experimental/v1"14)1516func ExampleListAllWorkspaces() {17token := "gitpod_pat_example.personal-access-token"1819gitpod, err := client.New(client.WithCredentials(token))20if err != nil {21fmt.Fprintf(os.Stderr, "Failed to construct gitpod client %v", err)22return23}2425response, err := gitpod.Workspaces.ListWorkspaces(context.Background(), connect.NewRequest(&v1.ListWorkspacesRequest{}))26if err != nil {27fmt.Fprintf(os.Stderr, "Failed to list workspaces %v", err)28return29}3031fmt.Fprintf(os.Stdout, "Retrieved workspaces %v", response.Msg.GetResult())32}3334func ExampleGetWorkspace() {35token := "gitpod_pat_example.personal-access-token"3637gitpod, err := client.New(client.WithCredentials(token))38if err != nil {39fmt.Fprintf(os.Stderr, "Failed to construct gitpod client %v", err)40return41}4243response, err := gitpod.Workspaces.GetWorkspace(context.Background(), connect.NewRequest(&v1.GetWorkspaceRequest{44WorkspaceId: "<WORKSPACE_ID>",45}))46if err != nil {47fmt.Fprintf(os.Stderr, "Failed to get workspace %v", err)48return49}5051fmt.Fprintf(os.Stdout, "Retrieved workspace %v", response.Msg.GetResult())52}535455