Skip to content

Commit 245cb43

Browse files
Siddhant-K-coderoboquat
authored andcommitted
examples: teams & workspaces examples in go
1 parent 7cbf80b commit 245cb43

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

components/public-api/go/examples/teams_example.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,23 @@ func ExampleListTeams() {
3434

3535
fmt.Fprintf(os.Stdout, "Retrieved teams %v", response.Msg.GetTeams())
3636
}
37+
38+
func ExampleGetTeam() {
39+
token := "gitpod_pat_example.personal-access-token"
40+
41+
gitpod, err := client.New(client.WithCredentials(token))
42+
if err != nil {
43+
fmt.Fprintf(os.Stderr, "Failed to construct gitpod client %v", err)
44+
return
45+
}
46+
47+
response, err := gitpod.Teams.GetTeam(context.Background(), connect.NewRequest(&v1.GetTeamRequest{
48+
TeamId: "<TEAM_ID>",
49+
}))
50+
if err != nil {
51+
fmt.Fprintf(os.Stderr, "Failed to get team %v", err)
52+
return
53+
}
54+
55+
fmt.Fprintf(os.Stdout, "Retrieved team %v", response.Msg.GetTeam())
56+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
}

0 commit comments

Comments
 (0)