func (s *storageClient) upload(ctx context.Context, r io.Reader, objectName string) error {
	w := s.client.Bucket(s.bucketName).Object(objectName).NewWriter(ctx)
	if _, err := io.Copy(w, r); err != nil {
		return fmt.Errorf("error while uploading to GCS object %q: %w", objectName, err)
	}
	if err := w.Close(); err != nil {
		return fmt.Errorf("error finishing upload to GCS object %q: %w", objectName, err)
	}
	return nil
}
upload uploads the bytes represented by the given reader as the given GCS object name.
package main
import (
	"bytes"
	"context"
	"encoding/json"
	"flag"
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"os"
	"time"
	"cloud.google.com/go/storage"
	"github.com/bazelbuild/bazel-toolchains/pkg/monitoring"
	"github.com/bazelbuild/bazel-toolchains/pkg/rbeconfigsgen"
)
var (
	configsTarball        = flag.String("configs_tarball", "", "Path to the configs tarball generated by rbe_configs_gen to be uploaded to GCS.")
	configsManifest       = flag.String("configs_manifest", "", "Path to the JSON manifest generated by rbe_configs_gen.")
	enableMonitoring      = flag.Bool("enable_monitoring", false, "(Optional) Enables reporting reporting results to Google Cloud Monitoring. Defaults to false.")
	monitoringProjectID   = flag.String("monitoring_project_id", "", "GCP Project ID where monitoring results will be reported. Required if --enable_monitoring is true.")
	monitoringDockerImage = flag.String("monitoring_docker_image", "", "Name of the toolchain docker image to be reported as a string label to monitoring. Required if --enable_monitoring is true.")
)
type manifest struct {
	rbeconfigsgen.Manifest
	UploadTime time.Time `json:"upload_time"`
}
func manifestFromFile(filePath string) (*manifest, error) {
	blob, err := ioutil.ReadFile(filePath)
	if err != nil {
		return nil, fmt.Errorf("unable to read manifest JSON file %q: %w", filePath, err)
	}
	m := &manifest{}
	if err := json.Unmarshal(blob, m); err != nil {
		return nil, fmt.Errorf("error parsing contents of manifest file %q as JSON: %w", filePath, err)
	}
	if len(m.BazelVersion) == 0 {
		return nil, fmt.Errorf("manifest %q did not specify bazel version", filePath)
	}
	m.UploadTime = time.Now()
	return m, nil
}
type storageClient struct {
	client *storage.Client
	bucketName string
}
func newStorage(ctx context.Context) (*storageClient, error) {
	c, err := storage.NewClient(ctx)
	if err != nil {
		return nil, err
	}
	return &storageClient{
		client:     c,
		bucketName: "rbe-toolchain",
	}, nil
}