storage

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 10 Imported by: 0

README

storage

Google Cloud Storage client wrapper for uploading, downloading, and managing objects.

Installation

go get github.com/louvri/gold/storage

Usage

Create Client
import "github.com/louvri/gold/storage"

client, err := storage.New(
    "credentials.json",       // path to file or raw JSON string
    "text/csv",               // content type for uploads
    "my-bucket",              // bucket name
    "",                       // custom endpoint (optional, leave empty for default)
    24*time.Hour,             // signed URL expiry duration
)
Upload
ctx := context.Background()

// Upload from file path
url, err := client.UploadByPath(ctx, "/path/to/file.csv")

// Upload from reader
url, err := client.UploadFromReader(ctx, "object-name.csv", reader)

Both return a signed URL for the uploaded object.

Download
// Download to file
err := client.DownloadToPath(ctx, "object-name.csv", "/path/to/dest.csv")

// Download to writer
var buf bytes.Buffer
err := client.Download(ctx, "object-name.csv", &buf)
Manage Objects
// List objects by prefix
names, err := client.List(ctx, "reports/")

// Check existence
exists, err := client.Exists(ctx, "object-name.csv")

// Delete
err := client.Delete(ctx, "object-name.csv")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	UploadByPath(ctx context.Context, path string) (*string, error)
	UploadFromReader(ctx context.Context, objectName string, reader io.Reader) (*string, error)
	DownloadToPath(ctx context.Context, objectName, destPath string) error
	Download(ctx context.Context, objectName string, writer io.Writer) error
	Delete(ctx context.Context, objectName string) error
	List(ctx context.Context, prefix string) ([]string, error)
	Exists(ctx context.Context, objectName string) (bool, error)
}

func New

func New(credential, contentType, bucketName, customEndpoint string, expiryDuration time.Duration) (Client, error)

Jump to

Keyboard shortcuts

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