aboutsummaryrefslogtreecommitdiff
path: root/vendor/google.golang.org/cloud/storage/storage.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/google.golang.org/cloud/storage/storage.go')
-rw-r--r--vendor/google.golang.org/cloud/storage/storage.go59
1 files changed, 40 insertions, 19 deletions
diff --git a/vendor/google.golang.org/cloud/storage/storage.go b/vendor/google.golang.org/cloud/storage/storage.go
index 75f0e55..1f667c1 100644
--- a/vendor/google.golang.org/cloud/storage/storage.go
+++ b/vendor/google.golang.org/cloud/storage/storage.go
@@ -68,50 +68,45 @@ const (
// AdminClient is a client type for performing admin operations on a project's
// buckets.
+//
+// Deprecated: Client has all of AdminClient's methods.
type AdminClient struct {
- hc *http.Client
- raw *raw.Service
+ c *Client
projectID string
}
// NewAdminClient creates a new AdminClient for a given project.
+//
+// Deprecated: use NewClient instead.
func NewAdminClient(ctx context.Context, projectID string, opts ...cloud.ClientOption) (*AdminClient, error) {
c, err := NewClient(ctx, opts...)
if err != nil {
return nil, err
}
return &AdminClient{
- hc: c.hc,
- raw: c.raw,
+ c: c,
projectID: projectID,
}, nil
}
// Close closes the AdminClient.
func (c *AdminClient) Close() error {
- c.hc = nil
- return nil
+ return c.c.Close()
}
// Create creates a Bucket in the project.
// If attrs is nil the API defaults will be used.
+//
+// Deprecated: use BucketHandle.Create instead.
func (c *AdminClient) CreateBucket(ctx context.Context, bucketName string, attrs *BucketAttrs) error {
- var bkt *raw.Bucket
- if attrs != nil {
- bkt = attrs.toRawBucket()
- } else {
- bkt = &raw.Bucket{}
- }
- bkt.Name = bucketName
- req := c.raw.Buckets.Insert(c.projectID, bkt)
- _, err := req.Context(ctx).Do()
- return err
+ return c.c.Bucket(bucketName).Create(ctx, c.projectID, attrs)
}
// Delete deletes a Bucket in the project.
+//
+// Deprecated: use BucketHandle.Delete instead.
func (c *AdminClient) DeleteBucket(ctx context.Context, bucketName string) error {
- req := c.raw.Buckets.Delete(bucketName)
- return req.Context(ctx).Do()
+ return c.c.Bucket(bucketName).Delete(ctx)
}
// Client is a client for interacting with Google Cloud Storage.
@@ -180,6 +175,27 @@ func (c *Client) Bucket(name string) *BucketHandle {
}
}
+// Create creates the Bucket in the project.
+// If attrs is nil the API defaults will be used.
+func (b *BucketHandle) Create(ctx context.Context, projectID string, attrs *BucketAttrs) error {
+ var bkt *raw.Bucket
+ if attrs != nil {
+ bkt = attrs.toRawBucket()
+ } else {
+ bkt = &raw.Bucket{}
+ }
+ bkt.Name = b.name
+ req := b.c.raw.Buckets.Insert(projectID, bkt)
+ _, err := req.Context(ctx).Do()
+ return err
+}
+
+// Delete deletes the Bucket.
+func (b *BucketHandle) Delete(ctx context.Context) error {
+ req := b.c.raw.Buckets.Delete(b.name)
+ return req.Context(ctx).Do()
+}
+
// ACL returns an ACLHandle, which provides access to the bucket's access control list.
// This controls who can list, create or overwrite the objects in a bucket.
// This call does not perform any network operations.
@@ -543,8 +559,13 @@ func (o *ObjectHandle) NewRangeReader(ctx context.Context, offset, length int64)
return nil, ErrObjectNotExist
}
if res.StatusCode < 200 || res.StatusCode > 299 {
+ body, _ := ioutil.ReadAll(res.Body)
res.Body.Close()
- return nil, fmt.Errorf("storage: can't read object %v/%v, status code: %v", o.bucket, o.object, res.Status)
+ return nil, &googleapi.Error{
+ Code: res.StatusCode,
+ Header: res.Header,
+ Body: string(body),
+ }
}
if offset > 0 && length != 0 && res.StatusCode != http.StatusPartialContent {
res.Body.Close()