Last active
March 18, 2020 10:23
-
-
Save saschagrunert/e51dd5dbe79efa83321fe9865b2e8e68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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