cloudstorage

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package cloudstorage implements the FileStore interface using Google Cloud Storage.

Index

Constants

View Source
const (
	// DefaultContentType is the default content type for files.
	DefaultContentType = "application/text"
	// ListTimeOut is the timeout for listing objects.
	ListTimeOut = 10 * time.Second
)
View Source
const (
	// DefaultUploadURLExpiry is the default expiry time for upload URLs.
	DefaultUploadURLExpiry = 5 * time.Minute
)

Variables

View Source
var ErrFileNotFound = fmt.Errorf("%w: file not found", storage.ErrNotFound)

ErrFileNotFound is returned when a file is not found.

Functions

This section is empty.

Types

type CloudStorage

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

CloudStorage is class that handles the Google Cloud Storage operations.

func New

func New(ctx context.Context, bucket *gcs.BucketHandle, accessID string, opts ...Opt) (*CloudStorage, error)

New creates a new CloudStorage instance.

func (*CloudStorage) CreateSignedURL

func (s *CloudStorage) CreateSignedURL(method, path, contentType string, expiry time.Time, queries url.Values) (string, error)

CreateSignedURL creates a signed URL for a file.

func (*CloudStorage) CreateUploadURL

func (s *CloudStorage) CreateUploadURL(path, contentType string) (string, time.Time, error)

CreateUploadURL creates a signed URL for uploading a file.

func (*CloudStorage) DeleteFile

func (s *CloudStorage) DeleteFile(ctx context.Context, path string) error

DeleteFile deletes a file from gcs.

func (*CloudStorage) DeleteFolder

func (s *CloudStorage) DeleteFolder(ctx context.Context, path string) error

DeleteFolder deletes a folder from gcs.

func (*CloudStorage) GetFile

func (s *CloudStorage) GetFile(ctx context.Context, path string, version int64, expiry time.Time) (*storage.File, error)

GetFile retrieves a downloadable URL for a file.

func (*CloudStorage) UploadFile

func (s *CloudStorage) UploadFile(ctx context.Context, path, contentType string, data []byte) error

UploadFile uploads a file to gcs.

type Opt

type Opt func(*CloudStorage)

Opt is a functional option for configuring a CloudStorage instance.

func WithCORS

func WithCORS(cors gcs.CORS) Opt

WithCORS sets the CORS configuration for the bucket.

func WithLogger

func WithLogger(l *zap.Logger) Opt

WithLogger sets the logger for the CloudStorage instance.

func WithUploadURLExpiry

func WithUploadURLExpiry(expiry time.Duration) Opt

WithUploadURLExpiry sets the expiry time for signed URLs.

Jump to

Keyboard shortcuts

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