/
main.go
39 lines (30 loc) · 851 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"log"
"cloud.google.com/go/storage"
"golang.org/x/net/context"
"google.golang.org/api/iterator"
)
func main() {
// ------------------ Using Google Cloud APIs --------------------------------
ctx := context.Background()
// with credential file
//storeageClient, err := storage.NewClient(ctx, option.WithCredentialsFile("/path/to/svc_account.json"))
// with env var
// export GOOGLE_APPLICATION_CREDENTIALS=/path/to/svc_account.json
storeageClient, err := storage.NewClient(ctx)
if err != nil {
log.Fatalf("Unable to acquire storage Client: %v", err)
}
it := storeageClient.Buckets(ctx, "YOUR_PROJECT_HERE")
for {
bucketAttrs, err := it.Next()
if err == iterator.Done {
break
}
if err != nil {
log.Fatalf("Unable to acquire storage Client: %v", err)
}
log.Printf(bucketAttrs.Name)
}
}