Skip to content

Storage Package Update

Andrew Gerrand edited this page Nov 24, 2015 · 1 revision

google.golang.org/cloud/storage update guide

November 24, 2015

The storage package has been modified to improve its exported API. Existing users of the package will need to update their code.

The changes include adding the Client type and improving consistency across naming and use of Access Control Lists.

In the previous version, users authenticated calls by using a context from google.golang.org/cloud package. For example:

cloud.WithContext(context.Background(), projectID, httpClient)

The new version introduces the Client type. Create a storage client using Default Application Credentials with one call (no need to specify a project ID):

ctx := context.Background()
client, err := storage.NewClient(ctx)

Then use the Client to perform calls, such as writing to a bucket:

bucketHandle := client.Bucket(bucketName)
w := bucketHandle.Object(objectName).NewWriter(ctx)

A full list of other changes (mostly renaming) is listed in the following table:

Before After
storage.BucketInfo(ctx, name) client.Bucket(name).Attrs(ctx)
storage.NewWriter(ctx, bucket, name) client.Bucket(bucket).Object(name).NewWriter(ctx)
storage.NewReader(ctx, bucket, name) client.Bucket(bucket).Object(name).NewReader(ctx)
storage.StatObject(ctx, bucket, name) client.Bucket(bucket).Object(name).Attrs(ctx)
storage.DeleteObject(ctx, bucket, name) client.Bucket(bucket).Object(name).Delete(ctx)
storage.UpdateAttrs(ctx, bucket, name) client.Bucket(bucket).Object(name).Update(ctx, attrs)
storage.Bucket storage.BucketAttrs
storage.Object storage.ObjectAttrs
storage.Objects storage.ObjectList

Access Control Lists

Before After
storage.ACL(ctx, bucket, object) bucket.Object(object).ACL().List(ctx)
storage.PutACLRule(ctx, bucket, object, entity, role) bucket.Object(object).ACL().Set(ctx, entity, role)
storage.DeleteACLRule(ctx, bucket, object, entity) bucket.Object(object).ACL().Delete(ctx, entity)
storage.BucketACL(ctx, bucket) bucket.ACL().List(ctx)
storage.PutBucketACLRule(ctx, bucket, entity, role) bucket.ACL().Set(ctx, entity, role)
storage.DeleteBucketACLRule(ctx, bucket, entity) bucket.ACL().Delete(ctx, entity)
storage.DefaultACL(ctx, bucket) bucket.DefaultACL().List(ctx)
storage.PutDefaultACLRule(ctx, bucket, entity, role) bucket.DefaultACL().Set(ctx, entity, role)
storage.DeleteDefaultACLRule(ctx, bucket, entity) bucket.DefaultACL().Delete(ctx, entity)