Path: blob/main/components/public-api/go/examples/teams_example.go
2500 views
// Copyright (c) 2022 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"github.com/bufbuild/connect-go"10"github.com/gitpod-io/gitpod/components/public-api/go/client"11v1 "github.com/gitpod-io/gitpod/components/public-api/go/experimental/v1"12"os"13"time"14)1516func ExampleListTeams() {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}2425ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)26defer cancel()2728response, err := gitpod.Teams.ListTeams(ctx, connect.NewRequest(&v1.ListTeamsRequest{}))29if err != nil {30fmt.Fprintf(os.Stderr, "Failed to list teams %v", err)31return32}3334fmt.Fprintf(os.Stdout, "Retrieved teams %v", response.Msg.GetTeams())35}3637func ExampleGetTeam() {38token := "gitpod_pat_example.personal-access-token"3940gitpod, err := client.New(client.WithCredentials(token))41if err != nil {42fmt.Fprintf(os.Stderr, "Failed to construct gitpod client %v", err)43return44}4546response, err := gitpod.Teams.GetTeam(context.Background(), connect.NewRequest(&v1.GetTeamRequest{47TeamId: "<TEAM_ID>",48}))49if err != nil {50fmt.Fprintf(os.Stderr, "Failed to get team %v", err)51return52}5354fmt.Fprintf(os.Stdout, "Retrieved team %v", response.Msg.GetTeam())55}565758