gitpod/components/public-api/go/examples/workspaces_example.go
2023-01-11 11:17:50 +01:00

54 lines
1.5 KiB
Go

// Copyright (c) 2023 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License.AGPL.txt in the project root for license information.
package examples
import (
"context"
"fmt"
"os"
"github.com/bufbuild/connect-go"
"github.com/gitpod-io/gitpod/components/public-api/go/client"
v1 "github.com/gitpod-io/gitpod/components/public-api/go/experimental/v1"
)
func ExampleListAllWorkspaces() {
token := "gitpod_pat_example.personal-access-token"
gitpod, err := client.New(client.WithCredentials(token))
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to construct gitpod client %v", err)
return
}
response, err := gitpod.Workspaces.ListWorkspaces(context.Background(), connect.NewRequest(&v1.ListWorkspacesRequest{}))
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to list workspaces %v", err)
return
}
fmt.Fprintf(os.Stdout, "Retrieved workspaces %v", response.Msg.GetResult())
}
func ExampleGetWorkspace() {
token := "gitpod_pat_example.personal-access-token"
gitpod, err := client.New(client.WithCredentials(token))
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to construct gitpod client %v", err)
return
}
response, err := gitpod.Workspaces.GetWorkspace(context.Background(), connect.NewRequest(&v1.GetWorkspaceRequest{
WorkspaceId: "<WORKSPACE_ID>",
}))
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to get workspace %v", err)
return
}
fmt.Fprintf(os.Stdout, "Retrieved workspace %v", response.Msg.GetResult())
}