gcsdriver

package module
v1.8.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package gcsdriver provides a Google Cloud Storage driver for Trove.

The GCS driver stores objects in Google Cloud Storage. It implements the core driver.Driver interface plus MultipartDriver, PresignDriver, and RangeDriver capability interfaces.

DSN format:

gcs://PROJECT_ID/BUCKET
gcs://PROJECT_ID/BUCKET?credentials=/path/to/key.json&endpoint=http://localhost:4443

Usage:

drv := gcsdriver.New()
drv.Open(ctx, "gcs://my-project/my-bucket")
t, err := trove.Open(drv)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GCSDriver

type GCSDriver struct {
	// contains filtered or unexported fields
}

GCSDriver implements driver.Driver for Google Cloud Storage.

func New

func New() *GCSDriver

New creates a new GCS storage driver.

func Unwrap

func Unwrap(t interface{ Driver() driver.Driver }) *GCSDriver

Unwrap extracts the typed GCSDriver from a Trove handle.

func (*GCSDriver) AbortMultipart

func (d *GCSDriver) AbortMultipart(ctx context.Context, bucket, key, uploadID string) error

AbortMultipart cancels a multipart upload and cleans up temporary objects.

func (*GCSDriver) Client

func (d *GCSDriver) Client() *storage.Client

Client returns the underlying GCS client for advanced use cases.

func (*GCSDriver) Close

func (d *GCSDriver) Close(_ context.Context) error

Close shuts down the GCS client.

func (*GCSDriver) CompleteMultipart

func (d *GCSDriver) CompleteMultipart(ctx context.Context, bucket, key, uploadID string, parts []driver.PartInfo) (*driver.ObjectInfo, error)

CompleteMultipart composes all part objects into the final object and cleans up.

func (*GCSDriver) Copy

func (d *GCSDriver) Copy(ctx context.Context, srcBucket, srcKey, dstBucket, dstKey string, _ ...driver.CopyOption) (*driver.ObjectInfo, error)

Copy copies an object within or across buckets.

func (*GCSDriver) CreateBucket

func (d *GCSDriver) CreateBucket(ctx context.Context, name string, _ ...driver.BucketOption) error

CreateBucket creates a new GCS bucket.

func (*GCSDriver) Delete

func (d *GCSDriver) Delete(ctx context.Context, bucket, key string, _ ...driver.DeleteOption) error

Delete removes an object from GCS.

func (*GCSDriver) DeleteBucket

func (d *GCSDriver) DeleteBucket(ctx context.Context, name string) error

DeleteBucket removes a GCS bucket.

func (*GCSDriver) Get

func (d *GCSDriver) Get(ctx context.Context, bucket, key string, _ ...driver.GetOption) (*driver.ObjectReader, error)

Get retrieves an object from GCS.

func (*GCSDriver) GetRange

func (d *GCSDriver) GetRange(ctx context.Context, bucket, key string, offset, length int64) (*driver.ObjectReader, error)

GetRange retrieves a byte range of an object. The offset is the starting byte position and length is the number of bytes to read. A length of -1 reads from offset to end.

func (*GCSDriver) Head

func (d *GCSDriver) Head(ctx context.Context, bucket, key string) (*driver.ObjectInfo, error)

Head returns object metadata without content.

func (*GCSDriver) InitiateMultipart

func (d *GCSDriver) InitiateMultipart(_ context.Context, bucket, key string, _ ...driver.PutOption) (string, error)

InitiateMultipart starts a multipart upload. GCS uses a compose pattern: parts are uploaded as temporary objects and composed into the final object.

func (*GCSDriver) List

func (d *GCSDriver) List(ctx context.Context, bucket string, opts ...driver.ListOption) (*driver.ObjectIterator, error)

List returns objects matching the given options.

func (*GCSDriver) ListBuckets

func (d *GCSDriver) ListBuckets(ctx context.Context) ([]driver.BucketInfo, error)

ListBuckets returns all accessible buckets.

func (*GCSDriver) Name

func (d *GCSDriver) Name() string

Name returns "gcs".

func (*GCSDriver) Open

func (d *GCSDriver) Open(ctx context.Context, dsn string, opts ...driver.Option) error

Open initializes the GCS client using the given DSN and options.

func (*GCSDriver) Ping

func (d *GCSDriver) Ping(ctx context.Context) error

Ping verifies GCS connectivity by checking bucket attributes.

func (*GCSDriver) PresignGet

func (d *GCSDriver) PresignGet(_ context.Context, bucket, key string, expires time.Duration) (string, error)

PresignGet generates a pre-signed URL for downloading an object.

func (*GCSDriver) PresignPut

func (d *GCSDriver) PresignPut(_ context.Context, bucket, key string, expires time.Duration) (string, error)

PresignPut generates a pre-signed URL for uploading an object.

func (*GCSDriver) Put

func (d *GCSDriver) Put(ctx context.Context, bucket, key string, r io.Reader, opts ...driver.PutOption) (*driver.ObjectInfo, error)

Put stores an object in GCS.

func (*GCSDriver) UploadPart

func (d *GCSDriver) UploadPart(ctx context.Context, bucket, key, uploadID string, partNum int, r io.Reader) (*driver.PartInfo, error)

UploadPart uploads a single part as a temporary GCS object.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL