github.com/jgbaldwinbrown/perf@v0.1.1/storage/fs/gcs/gcs.go (about)

     1  // Copyright 2016 The Go Authors.  All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Package gcs implements the fs.FS interface using Google Cloud Storage.
     6  package gcs
     7  
     8  import (
     9  	"cloud.google.com/go/storage"
    10  	"golang.org/x/net/context"
    11  	"golang.org/x/perf/storage/fs"
    12  )
    13  
    14  // impl is an fs.FS backed by Google Cloud Storage.
    15  type impl struct {
    16  	bucket *storage.BucketHandle
    17  }
    18  
    19  // NewFS constructs an FS that writes to the provided bucket.
    20  // On AppEngine, ctx must be a request-derived Context.
    21  func NewFS(ctx context.Context, bucketName string) (fs.FS, error) {
    22  	client, err := storage.NewClient(ctx)
    23  	if err != nil {
    24  		return nil, err
    25  	}
    26  	return &impl{client.Bucket(bucketName)}, nil
    27  }
    28  
    29  func (fs *impl) NewWriter(ctx context.Context, name string, metadata map[string]string) (fs.Writer, error) {
    30  	w := fs.bucket.Object(name).NewWriter(ctx)
    31  	// TODO(quentin): Do these need "x-goog-meta-" prefixes?
    32  	w.Metadata = metadata
    33  	return w, nil
    34  }