本文整理匯總了Golang中cloud/google/com/go/storage.Client.Close方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.Close方法的具體用法?Golang Client.Close怎麽用?Golang Client.Close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cloud/google/com/go/storage.Client
的用法示例。
在下文中一共展示了Client.Close方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: initSinks
// Called just before TestMain calls m.Run.
// Returns a cleanup function to be called after the tests finish.
func initSinks(ctx context.Context) func() {
// Create a unique GCS bucket so concurrent tests don't interfere with each other.
testBucketPrefix := testProjectID + "-log-sink"
testBucket := ltesting.UniqueID(testBucketPrefix)
testSinkDestination = "storage.googleapis.com/" + testBucket
var storageClient *storage.Client
if integrationTest {
// Create a unique bucket as a sink destination, and give the cloud logging account
// owner right.
ts := testutil.TokenSource(ctx, storage.ScopeFullControl)
var err error
storageClient, err = storage.NewClient(ctx, option.WithTokenSource(ts))
if err != nil {
log.Fatalf("new storage client: %v", err)
}
bucket := storageClient.Bucket(testBucket)
if err := bucket.Create(ctx, testProjectID, nil); err != nil {
log.Fatalf("creating storage bucket %q: %v", testBucket, err)
}
if err := bucket.ACL().Set(ctx, "[email protected]", storage.RoleOwner); err != nil {
log.Fatalf("setting owner role: %v", err)
}
}
// Clean up from aborted tests.
for _, sID := range ltesting.ExpiredUniqueIDs(sinkIDs(ctx), testSinkIDPrefix) {
client.DeleteSink(ctx, sID) // ignore error
}
if integrationTest {
for _, bn := range ltesting.ExpiredUniqueIDs(bucketNames(ctx, storageClient), testBucketPrefix) {
storageClient.Bucket(bn).Delete(ctx) // ignore error
}
return func() {
if err := storageClient.Bucket(testBucket).Delete(ctx); err != nil {
log.Printf("deleting %q: %v", testBucket, err)
}
storageClient.Close()
}
}
return func() {}
}