本文整理匯總了Golang中cloud/google/com/go/storage.Client.Buckets方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.Buckets方法的具體用法?Golang Client.Buckets怎麽用?Golang Client.Buckets使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cloud/google/com/go/storage.Client
的用法示例。
在下文中一共展示了Client.Buckets方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: list
func list(client *storage.Client, projectID string) ([]string, error) {
ctx := context.Background()
// [START list_buckets]
var buckets []string
it := client.Buckets(ctx, projectID)
for {
battrs, err := it.Next()
if err == iterator.Done {
break
}
if err != nil {
return nil, err
}
buckets = append(buckets, battrs.Name)
}
// [END list_buckets]
return buckets, nil
}
示例2: bucketNames
// Collect the name of all buckets for the test project.
func bucketNames(ctx context.Context, client *storage.Client) []string {
var names []string
it := client.Buckets(ctx, testProjectID)
loop:
for {
b, err := it.Next()
switch err {
case nil:
names = append(names, b.Name)
case iterator.Done:
break loop
default:
log.Printf("listing buckets: %v", err)
break loop
}
}
return names
}