// ListGroups lists the existing groups. func (c *GroupClient) ListGroups(ctx context.Context, req *monitoringpb.ListGroupsRequest) *GroupIterator { md, _ := metadata.FromContext(ctx) ctx = metadata.NewContext(ctx, metadata.Join(md, c.metadata)) it := &GroupIterator{} it.InternalFetch = func(pageSize int, pageToken string) ([]*monitoringpb.Group, string, error) { var resp *monitoringpb.ListGroupsResponse req.PageToken = pageToken if pageSize > math.MaxInt32 { req.PageSize = math.MaxInt32 } else { req.PageSize = int32(pageSize) } err := gax.Invoke(ctx, func(ctx context.Context) error { var err error resp, err = c.groupClient.ListGroups(ctx, req) return err }, c.CallOptions.ListGroups...) if err != nil { return nil, "", err } return resp.Group, resp.NextPageToken, nil } fetch := func(pageSize int, pageToken string) (string, error) { items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) if err != nil { return "", err } it.items = append(it.items, items...) return nextPageToken, nil } it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) return it }
// ListGroups lists the existing groups. The project ID in the URL path must refer // to a Stackdriver account. func (c *GroupClient) ListGroups(ctx context.Context, req *monitoringpb.ListGroupsRequest) *GroupIterator { ctx = metadata.NewContext(ctx, c.metadata) it := &GroupIterator{} it.apiCall = func() error { var resp *monitoringpb.ListGroupsResponse err := gax.Invoke(ctx, func(ctx context.Context) error { var err error req.PageToken = it.nextPageToken req.PageSize = it.pageSize resp, err = c.client.ListGroups(ctx, req) return err }, c.CallOptions.ListGroups...) if err != nil { return err } if resp.NextPageToken == "" { it.atLastPage = true } it.nextPageToken = resp.NextPageToken it.items = resp.Group return nil } return it }