golang.org/x/build@v0.0.0-20240506185731-218518f32b70/perfdata/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 "context" 10 11 "cloud.google.com/go/storage" 12 "golang.org/x/build/perfdata/fs" 13 ) 14 15 // impl is an fs.FS backed by Google Cloud Storage. 16 type impl struct { 17 bucket *storage.BucketHandle 18 } 19 20 // NewFS constructs an FS that writes to the provided bucket. 21 // On AppEngine, ctx must be a request-derived Context. 22 func NewFS(ctx context.Context, bucketName string) (fs.FS, error) { 23 client, err := storage.NewClient(ctx) 24 if err != nil { 25 return nil, err 26 } 27 return &impl{client.Bucket(bucketName)}, nil 28 } 29 30 func (fs *impl) NewWriter(ctx context.Context, name string, metadata map[string]string) (fs.Writer, error) { 31 w := fs.bucket.Object(name).NewWriter(ctx) 32 // TODO(quentin): Do these need "x-goog-meta-" prefixes? 33 w.Metadata = metadata 34 return w, nil 35 }