Skip to content

Instantly share code, notes, and snippets.

@saschagrunert
Last active March 18, 2020 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saschagrunert/e51dd5dbe79efa83321fe9865b2e8e68 to your computer and use it in GitHub Desktop.
Save saschagrunert/e51dd5dbe79efa83321fe9865b2e8e68 to your computer and use it in GitHub Desktop.
package main
// BEFORE RUNNING:
// ---------------
// 1. If not already done, enable the Cloud Resource Manager API
// and check the quota for your project at
// https://console.developers.google.com/apis/api/cloudresourcemanager
// 2. This sample uses Application Default Credentials for authentication.
// If not already done, install the gcloud CLI from
// https://cloud.google.com/sdk/ and run
// `gcloud beta auth application-default login`.
// For more information, see
// https://developers.google.com/identity/protocols/application-default-credentials
// 3. Install and update the Go dependencies by running `go get -u` in the
// project directory.
import (
"fmt"
"log"
"golang.org/x/net/context"
"google.golang.org/api/cloudresourcemanager/v1"
"google.golang.org/api/option"
)
func main() {
ctx := context.Background()
opts := option.WithCredentialsFile("")
service, err := cloudresourcemanager.NewService(ctx, opts)
if err != nil {
log.Fatal(err)
}
req := service.Projects.List()
if err := req.Pages(ctx, func(page *cloudresourcemanager.ListProjectsResponse) error {
for _, project := range page.Projects {
fmt.Printf("%#v\n", project)
}
return nil
}); err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment