func (g *GoogleCloudStorageBackend) Delete(ctx context.Context, filename string) error {
	return g.client.Bucket(g.bucketName).Object(g.prefix + filename).Delete(ctx)
}
Delete will delete the given object from the configured bucket
package backends
import (
	"context"
	"fmt"
	"io"
	"strings"
	"cloud.google.com/go/storage"
	"google.golang.org/api/iterator"
	"google.golang.org/api/option"
	"github.com/someone1/zfsbackup-go/files"
	"github.com/someone1/zfsbackup-go/log"
)
const GoogleCloudStorageBackendPrefix = "gs"
type GoogleCloudStorageBackend struct {
	conf       *BackendConfig
	client     *storage.Client
	prefix     string
	bucketName string
}
type withGoogleCloudStorageClient struct{ client *storage.Client }
func (w withGoogleCloudStorageClient) Apply(b Backend) {
	if v, ok := b.(*GoogleCloudStorageBackend); ok {
		v.client = w.client
	}
}
func WithGoogleCloudStorageClient(c *storage.Client) Option {
	return withGoogleCloudStorageClient{c}
}
func (g *GoogleCloudStorageBackend) Init(ctx context.Context, conf *BackendConfig, opts ...Option) error {
	g.conf = conf
	cleanPrefix := strings.TrimPrefix(g.conf.TargetURI, "gs://")
	if cleanPrefix == g.conf.TargetURI {
		return ErrInvalidURI
	}
	uriParts := strings.Split(cleanPrefix, "/")
	g.bucketName = uriParts[0]
	if len(uriParts) > 1 {
		g.prefix = strings.Join(uriParts[1:], "/")
	}
	for _, opt := range opts {
		opt.Apply(g)
	}
	if g.client == nil {
		client, err := storage.NewClient(ctx, option.WithScopes(storage.ScopeReadWrite))
		if err != nil {
			return err
		}
		g.client = client
	}
	if _, err := g.client.Bucket(g.bucketName).Attrs(ctx); err != nil {
		return err
	}
	return nil
}
func (g *GoogleCloudStorageBackend) Upload(ctx context.Context, vol *files.VolumeInfo) error {
	ctx, cancel := context.WithCancel(ctx)
	defer cancel()
	g.conf.MaxParallelUploadBuffer <- true
	defer func() {
		<-g.conf.MaxParallelUploadBuffer
	}()
	objName := g.prefix + vol.ObjectName
	w := g.client.Bucket(g.bucketName).Object(objName).NewWriter(ctx)
	w.CRC32C = vol.CRC32CSum32
	w.SendCRC32C = true
	w.ChunkSize = g.conf.UploadChunkSize
	if _, err := io.Copy(w, vol); err != nil {
		log.AppLogger.Debugf("gs backend: Error while uploading volume %s - %v", vol.ObjectName, err)
		return err
	}
	return w.Close()
}