Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/public-api/go/examples/workspaces_example.go
2500 views
1
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package examples
6
7
import (
8
"context"
9
"fmt"
10
"os"
11
12
"github.com/bufbuild/connect-go"
13
"github.com/gitpod-io/gitpod/components/public-api/go/client"
14
v1 "github.com/gitpod-io/gitpod/components/public-api/go/experimental/v1"
15
)
16
17
func ExampleListAllWorkspaces() {
18
token := "gitpod_pat_example.personal-access-token"
19
20
gitpod, err := client.New(client.WithCredentials(token))
21
if err != nil {
22
fmt.Fprintf(os.Stderr, "Failed to construct gitpod client %v", err)
23
return
24
}
25
26
response, err := gitpod.Workspaces.ListWorkspaces(context.Background(), connect.NewRequest(&v1.ListWorkspacesRequest{}))
27
if err != nil {
28
fmt.Fprintf(os.Stderr, "Failed to list workspaces %v", err)
29
return
30
}
31
32
fmt.Fprintf(os.Stdout, "Retrieved workspaces %v", response.Msg.GetResult())
33
}
34
35
func ExampleGetWorkspace() {
36
token := "gitpod_pat_example.personal-access-token"
37
38
gitpod, err := client.New(client.WithCredentials(token))
39
if err != nil {
40
fmt.Fprintf(os.Stderr, "Failed to construct gitpod client %v", err)
41
return
42
}
43
44
response, err := gitpod.Workspaces.GetWorkspace(context.Background(), connect.NewRequest(&v1.GetWorkspaceRequest{
45
WorkspaceId: "<WORKSPACE_ID>",
46
}))
47
if err != nil {
48
fmt.Fprintf(os.Stderr, "Failed to get workspace %v", err)
49
return
50
}
51
52
fmt.Fprintf(os.Stdout, "Retrieved workspace %v", response.Msg.GetResult())
53
}
54
55