objstore

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: MIT Imports: 14 Imported by: 0

README

objstore

Go Reference Go Report Card Go Version CI GitHub tag codecov

Unified file storage interface for Go, supporting local filesystem, AWS S3, Google Cloud Storage, Azure Blob Storage, and in-memory storage for testing.

Installation

go get github.com/KARTIKrocks/objstore

Quick Start

import "github.com/KARTIKrocks/objstore"

// Local storage
store, _ := objstore.NewLocalStorage(
    objstore.DefaultLocalConfig().WithBasePath("./uploads"),
)

// Upload file
file, _ := os.Open("document.pdf")
info, _ := store.Put(ctx, "docs/document.pdf", file)

// Download file
reader, _ := store.Get(ctx, "docs/document.pdf")
defer reader.Close()

// Delete file
store.Delete(ctx, "docs/document.pdf")

Storage Backends

Local Storage
config := objstore.LocalConfig{
    BasePath:        "./storage",
    BaseURL:         "https://example.com/files",
    CreateDirs:      true,
    FilePermissions: 0644,
    DirPermissions:  0755,
}

store, err := objstore.NewLocalStorage(config)

// Or with builder pattern
store, err := objstore.NewLocalStorage(
    objstore.DefaultLocalConfig().
        WithBasePath("/var/uploads").
        WithBaseURL("https://cdn.example.com"),
)
AWS S3
import "github.com/KARTIKrocks/objstore/s3"

store, err := s3.New(ctx,
    s3.DefaultConfig().
        WithBucket("my-bucket").
        WithRegion("us-west-2").
        WithCredentials("ACCESS_KEY", "SECRET_KEY"),
)

// With custom endpoint (MinIO, DigitalOcean Spaces, etc.)
store, err := s3.New(ctx,
    s3.DefaultConfig().
        WithBucket("my-bucket").
        WithEndpoint("https://nyc3.digitaloceanspaces.com").
        WithPathStyle(true),
)

// With IAM role (no credentials needed)
store, err := s3.New(ctx,
    s3.DefaultConfig().
        WithBucket("my-bucket").
        WithRegion("us-east-1"),
)

// With path prefix
store, err := s3.New(ctx,
    s3.DefaultConfig().
        WithBucket("my-bucket").
        WithPrefix("uploads/user-123"),
)
Google Cloud Storage
import "github.com/KARTIKrocks/objstore/gcs"

store, err := gcs.New(ctx,
    gcs.DefaultConfig().
        WithBucket("my-bucket").
        WithCredentialsFile("/path/to/service-account.json"),
)

// With credentials JSON
store, err := gcs.New(ctx,
    gcs.DefaultConfig().
        WithBucket("my-bucket").
        WithCredentialsJSON(jsonBytes),
)

// With authorized user credentials (non-default type)
store, err := gcs.New(ctx,
    gcs.DefaultConfig().
        WithBucket("my-bucket").
        WithCredentialsFile("/path/to/authorized-user.json").
        WithCredentialsType(option.AuthorizedUser),
)

// With default credentials (GCE, Cloud Run, etc.)
store, err := gcs.New(ctx,
    gcs.DefaultConfig().
        WithBucket("my-bucket"),
)

defer store.Close()
Azure Blob Storage
import "github.com/KARTIKrocks/objstore/azure"

// With account name and key
store, err := azure.New(ctx,
    azure.DefaultConfig().
        WithAccountName("myaccount").
        WithAccountKey("mykey").
        WithContainerName("mycontainer"),
)

// With connection string
store, err := azure.New(ctx,
    azure.DefaultConfig().
        WithConnectionString("DefaultEndpointsProtocol=https;AccountName=...").
        WithContainerName("mycontainer"),
)

// With default Azure credentials (managed identity, env vars, CLI)
store, err := azure.New(ctx,
    azure.DefaultConfig().
        WithAccountName("myaccount").
        WithContainerName("mycontainer"),
)
In-Memory Storage (Testing)
store := objstore.NewMemoryStorage()

// Upload
store.Put(ctx, "test.txt", strings.NewReader("hello"))

// Verify
data, _ := objstore.GetBytes(ctx, store, "test.txt")
fmt.Println(string(data)) // "hello"

// Clear all
store.Clear()

Core Operations

Upload
// From io.Reader
file, _ := os.Open("photo.jpg")
info, err := store.Put(ctx, "images/photo.jpg", file)

// With options
info, err := store.Put(ctx, "images/photo.jpg", file,
    objstore.WithContentType("image/jpeg"),
    objstore.WithMetadata(map[string]string{"author": "john"}),
    objstore.WithCacheControl("max-age=31536000"),
    objstore.WithACL("public-read"),
)

// Prevent overwrite
info, err := store.Put(ctx, "images/photo.jpg", file,
    objstore.WithOverwrite(false),
)
if err == objstore.ErrAlreadyExists {
    // File already exists
}

// Helper functions
objstore.PutBytes(ctx, store, "data.bin", []byte{1, 2, 3})
objstore.PutString(ctx, store, "hello.txt", "Hello, World!")
objstore.PutDataURI(ctx, store, "image.png", "data:image/png;base64,...")
Download
// As io.ReadCloser
reader, err := store.Get(ctx, "docs/file.pdf")
if err == objstore.ErrNotFound {
    // File doesn't exist
}
defer reader.Close()
io.Copy(dst, reader)

// Helper functions
data, _ := objstore.GetBytes(ctx, store, "data.bin")
text, _ := objstore.GetString(ctx, store, "hello.txt")
Delete
err := store.Delete(ctx, "images/photo.jpg")

// Delete with prefix (all files in directory)
objstore.DeletePrefix(ctx, store, "images/user-123/")

// S3: Batch delete multiple files
s3Store.DeleteMultiple(ctx, []string{"file1.txt", "file2.txt"})
Check Existence
exists, err := store.Exists(ctx, "images/photo.jpg")
File Information
info, err := store.Stat(ctx, "images/photo.jpg")

fmt.Println(info.Path)         // "images/photo.jpg"
fmt.Println(info.Name)         // "photo.jpg"
fmt.Println(info.Size)         // 12345
fmt.Println(info.ContentType)  // "image/jpeg"
fmt.Println(info.LastModified) // 2026-03-16 10:30:00
fmt.Println(info.ETag)         // "abc123"
fmt.Println(info.Metadata)     // map[author:john]
List Files
// List files in directory
result, err := store.List(ctx, "images/")

for _, file := range result.Files {
    fmt.Println(file.Path, file.Size)
}

// List subdirectories
for _, prefix := range result.Prefixes {
    fmt.Println("Directory:", prefix)
}

// With options
result, err := store.List(ctx, "images/",
    objstore.WithMaxKeys(100),
    objstore.WithDelimiter("/"),
    objstore.WithRecursive(true),
)

// Pagination
for {
    result, _ := store.List(ctx, "images/",
        objstore.WithMaxKeys(100),
        objstore.WithToken(nextToken),
    )

    // Process files...

    if !result.IsTruncated {
        break
    }
    nextToken = result.NextToken
}
Copy and Move
// Copy
err := store.Copy(ctx, "images/original.jpg", "images/backup.jpg")

// Move (rename)
err := store.Move(ctx, "temp/upload.jpg", "images/photo.jpg")

// Copy between storages
objstore.CopyTo(ctx, srcStore, "file.txt", dstStore, "file.txt")

// Move between storages
objstore.MoveTo(ctx, srcStore, "file.txt", dstStore, "file.txt")
URLs
// Public URL
url, err := store.URL(ctx, "images/photo.jpg")
// "https://cdn.example.com/images/photo.jpg"

// Signed URL (temporary access)
url, err := store.SignedURL(ctx, "images/photo.jpg",
    objstore.WithExpires(15 * time.Minute),
)

// Signed URL for upload
url, err := store.SignedURL(ctx, "uploads/new-file.jpg",
    objstore.WithMethod("PUT"),
    objstore.WithExpires(5 * time.Minute),
    objstore.WithSignedContentType("image/jpeg"),
)

Helper Functions

Path Generation
// Generate unique filename
filename := objstore.GenerateFileName("photo.jpg")
// "550e8400-e29b-41d4-a716-446655440000.jpg"

// Generate date-based path
path := objstore.GeneratePath("photo.jpg", "uploads")
// "uploads/2024/01/15/550e8400-e29b-41d4-a716-446655440000.jpg"

// Generate hash-distributed path
path := objstore.GenerateHashedPath("photo.jpg", "uploads", 2)
// "uploads/55/0e/550e8400-e29b-41d4-a716-446655440000.jpg"
File Type Detection
info, _ := store.Stat(ctx, "file.jpg")

objstore.IsImage(info)    // true
objstore.IsVideo(info)    // false
objstore.IsAudio(info)    // false
objstore.IsDocument(info) // false
Size Formatting
objstore.FormatSize(1024)       // "1.0 KB"
objstore.FormatSize(1048576)    // "1.0 MB"
objstore.FormatSize(1073741824) // "1.0 GB"
Sync Directory
// Upload entire directory to storage
objstore.SyncDir(ctx, store, "./local/files", "remote/files")

Switching Backends

All backends implement the same objstore.Storage interface:

var store objstore.Storage

switch env {
case "development":
    store = objstore.NewMemoryStorage()
case "local":
    store, _ = objstore.NewLocalStorage(objstore.DefaultLocalConfig())
case "production-s3":
    store, _ = s3.New(ctx, s3.DefaultConfig().
        WithBucket(os.Getenv("S3_BUCKET")))
case "production-gcs":
    store, _ = gcs.New(ctx, gcs.DefaultConfig().
        WithBucket(os.Getenv("GCS_BUCKET")))
case "production-azure":
    store, _ = azure.New(ctx, azure.DefaultConfig().
        WithAccountName(os.Getenv("AZURE_ACCOUNT")).
        WithContainerName(os.Getenv("AZURE_CONTAINER")))
}

// Same API for all backends
store.Put(ctx, "file.txt", reader)
store.Get(ctx, "file.txt")
store.Delete(ctx, "file.txt")

Error Handling

_, err := store.Get(ctx, "missing.txt")

switch {
case errors.Is(err, objstore.ErrNotFound):
    // File doesn't exist
case errors.Is(err, objstore.ErrAlreadyExists):
    // File already exists (when overwrite=false)
case errors.Is(err, objstore.ErrInvalidPath):
    // Invalid path (e.g., path traversal attempt)
case errors.Is(err, objstore.ErrPermission):
    // Permission denied
case errors.Is(err, objstore.ErrNotImplemented):
    // Operation not supported by this backend
default:
    // Other error
}

ACL Values

Common ACL values for S3 and GCS:

ACL Description
private Owner-only access (default)
public-read Public read access
public-read-write Public read/write access
authenticated-read Authenticated users can read
bucket-owner-full-control Bucket owner has full control

Documentation

Overview

Package objstore provides a unified interface for file storage operations across multiple cloud and local backends.

Supported backends:

  • Local filesystem (objstore.LocalStorage)
  • AWS S3 and S3-compatible services (s3.Storage)
  • Google Cloud Storage (gcs.Storage)
  • Azure Blob Storage (azure.Storage)
  • In-memory for testing (objstore.MemoryStorage)

All backends implement the Storage interface, allowing seamless switching between providers without changing application code.

Quick Start

// Create a storage backend
store, err := objstore.NewLocalStorage(
    objstore.DefaultLocalConfig().WithBasePath("./uploads"),
)
if err != nil {
    log.Fatal(err)
}

// Upload
info, err := store.Put(ctx, "images/photo.jpg", file,
    objstore.WithContentType("image/jpeg"),
)

// Download
reader, err := store.Get(ctx, "images/photo.jpg")
defer reader.Close()

// Delete
err = store.Delete(ctx, "images/photo.jpg")

Backend Selection

Use the same interface across environments:

var store objstore.Storage
switch env {
case "test":
    store = objstore.NewMemoryStorage()
case "local":
    store, _ = objstore.NewLocalStorage(objstore.DefaultLocalConfig())
case "production":
    store, _ = s3.New(ctx, s3.DefaultConfig().WithBucket("my-bucket"))
}

Upload Options

Use functional options to configure uploads:

store.Put(ctx, path, reader,
    objstore.WithContentType("image/png"),
    objstore.WithMetadata(map[string]string{"owner": "alice"}),
    objstore.WithCacheControl("max-age=86400"),
    objstore.WithACL("public-read"),
    objstore.WithOverwrite(false),
)

Package objstore provides a unified interface for file storage operations across different backends including local filesystem, AWS S3, Google Cloud Storage, and Azure Blob Storage.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound       = errors.New("objstore: file not found")
	ErrAlreadyExists  = errors.New("objstore: file already exists")
	ErrInvalidPath    = errors.New("objstore: invalid path")
	ErrPermission     = errors.New("objstore: permission denied")
	ErrNotImplemented = errors.New("objstore: operation not implemented")
	ErrInvalidConfig  = errors.New("objstore: invalid configuration")
)

Sentinel errors for storage operations.

Functions

func CopyTo

func CopyTo(ctx context.Context, src Storage, srcPath string, dst Storage, dstPath string, opts ...PutOption) error

CopyTo copies a file from one storage to another.

func DeletePrefix

func DeletePrefix(ctx context.Context, s Storage, prefix string) error

DeletePrefix deletes all files matching a prefix. If the storage backend implements BatchDeleter, it uses batch deletion for efficiency.

func DetectContentType

func DetectContentType(path string) string

DetectContentType detects the MIME type from file extension.

func FormatSize

func FormatSize(size int64) string

FormatSize formats a file size in human-readable format.

func GenerateFileName

func GenerateFileName(originalName string) string

GenerateFileName generates a unique filename with the original extension.

func GenerateHashedPath

func GenerateHashedPath(originalName string, prefix string, levels int) string

GenerateHashedPath generates a path using hash-based distribution. This helps distribute files across directories when you have many files.

func GeneratePath

func GeneratePath(originalName string, prefix string) string

GeneratePath generates a unique path with date-based organization.

func GetBytes

func GetBytes(ctx context.Context, s Storage, path string) ([]byte, error)

GetBytes retrieves content as bytes.

func GetString

func GetString(ctx context.Context, s Storage, path string) (string, error)

GetString retrieves content as a string.

func IsAudio

func IsAudio(info *FileInfo) bool

IsAudio checks if a file is audio based on its content type.

func IsDocument

func IsDocument(info *FileInfo) bool

IsDocument checks if a file is a document (PDF, Word, Excel, etc.).

func IsImage

func IsImage(info *FileInfo) bool

IsImage checks if a file is an image based on its content type.

func IsVideo

func IsVideo(info *FileInfo) bool

IsVideo checks if a file is a video based on its content type.

func MoveTo

func MoveTo(ctx context.Context, src Storage, srcPath string, dst Storage, dstPath string, opts ...PutOption) error

MoveTo moves a file from one storage to another.

func NormalizePath

func NormalizePath(path string) string

NormalizePath normalizes a path for consistent storage.

func ParseDataURI

func ParseDataURI(dataURI string) ([]byte, string, error)

ParseDataURI parses a data URI and returns the content and MIME type.

func SyncDir

func SyncDir(ctx context.Context, s Storage, localPath, remotePath string) error

SyncDir synchronizes a local directory to storage.

Types

type BatchDeleter

type BatchDeleter interface {
	DeleteMultiple(ctx context.Context, paths []string) error
}

BatchDeleter is an optional interface for backends that support batch deletion.

type FileInfo

type FileInfo struct {
	Path         string            // Full path including filename
	Name         string            // Filename only
	Size         int64             // Size in bytes
	ContentType  string            // MIME type
	ETag         string            // Entity tag for versioning
	LastModified time.Time         // Last modification time
	Metadata     map[string]string // Custom metadata
	IsDir        bool              // True if this is a directory/prefix
}

FileInfo contains information about a stored file.

func PutBytes

func PutBytes(ctx context.Context, s Storage, path string, data []byte, opts ...PutOption) (*FileInfo, error)

PutBytes uploads bytes to storage.

func PutDataURI

func PutDataURI(ctx context.Context, s Storage, path string, dataURI string, opts ...PutOption) (*FileInfo, error)

PutDataURI uploads content from a data URI.

func PutString

func PutString(ctx context.Context, s Storage, path string, data string, opts ...PutOption) (*FileInfo, error)

PutString uploads a string to storage.

type ListOption

type ListOption func(*ListOptions)

ListOption is a function that modifies ListOptions.

func WithDelimiter

func WithDelimiter(delimiter string) ListOption

WithDelimiter sets the delimiter for grouping.

func WithMaxKeys

func WithMaxKeys(maxKeys int) ListOption

WithMaxKeys sets the maximum number of results.

func WithRecursive

func WithRecursive(recursive bool) ListOption

WithRecursive enables recursive listing.

func WithToken

func WithToken(token string) ListOption

WithToken sets the continuation token.

type ListOptions

type ListOptions struct {
	MaxKeys   int    // Maximum number of results
	Delimiter string // Delimiter for grouping (e.g., "/")
	Token     string // Continuation token for pagination
	Recursive bool   // List recursively (ignore delimiter)
}

ListOptions configures list behavior.

func ApplyListOptions

func ApplyListOptions(opts []ListOption) *ListOptions

ApplyListOptions applies ListOption functions to ListOptions.

type ListResult

type ListResult struct {
	Files       []*FileInfo // Files matching the prefix
	Prefixes    []string    // Common prefixes (directories)
	NextToken   string      // Token for pagination
	IsTruncated bool        // True if there are more results
}

ListResult contains the result of a list operation.

type LocalConfig

type LocalConfig struct {
	// BasePath is the root directory for storage.
	BasePath string

	// BaseURL is the public URL prefix for serving files.
	BaseURL string

	// CreateDirs automatically creates directories when uploading.
	CreateDirs bool

	// Permissions for created files (default: 0644).
	FilePermissions os.FileMode

	// Permissions for created directories (default: 0755).
	DirPermissions os.FileMode
}

LocalConfig holds configuration for local filesystem storage.

func DefaultLocalConfig

func DefaultLocalConfig() LocalConfig

DefaultLocalConfig returns a default local storage configuration.

func (LocalConfig) WithBasePath

func (c LocalConfig) WithBasePath(path string) LocalConfig

WithBasePath returns a new config with the specified base path.

func (LocalConfig) WithBaseURL

func (c LocalConfig) WithBaseURL(url string) LocalConfig

WithBaseURL returns a new config with the specified base URL.

func (LocalConfig) WithCreateDirs

func (c LocalConfig) WithCreateDirs(create bool) LocalConfig

WithCreateDirs returns a new config with auto directory creation.

func (LocalConfig) WithPermissions

func (c LocalConfig) WithPermissions(file, dir os.FileMode) LocalConfig

WithPermissions returns a new config with the specified permissions.

type LocalStorage

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

LocalStorage implements Storage for local filesystem.

func NewLocalStorage

func NewLocalStorage(config LocalConfig) (*LocalStorage, error)

NewLocalStorage creates a new local filesystem storage.

func (*LocalStorage) Close

func (s *LocalStorage) Close() error

Close is a no-op for local storage.

func (*LocalStorage) Copy

func (s *LocalStorage) Copy(ctx context.Context, src, dst string) error

Copy copies a file.

func (*LocalStorage) Delete

func (s *LocalStorage) Delete(ctx context.Context, path string) error

Delete removes a file from the local filesystem.

func (*LocalStorage) DeleteDir

func (s *LocalStorage) DeleteDir(ctx context.Context, path string) error

DeleteDir removes a directory and all its contents.

func (*LocalStorage) Exists

func (s *LocalStorage) Exists(ctx context.Context, path string) (bool, error)

Exists checks if a file exists on the local filesystem.

func (*LocalStorage) Get

func (s *LocalStorage) Get(ctx context.Context, path string) (io.ReadCloser, error)

Get retrieves content from the local filesystem.

func (*LocalStorage) List

func (s *LocalStorage) List(ctx context.Context, prefix string, opts ...ListOption) (*ListResult, error)

List returns files matching the prefix.

func (*LocalStorage) Move

func (s *LocalStorage) Move(ctx context.Context, src, dst string) error

Move moves a file.

func (*LocalStorage) Put

func (s *LocalStorage) Put(ctx context.Context, path string, reader io.Reader, opts ...PutOption) (*FileInfo, error)

Put uploads content to the local filesystem.

func (*LocalStorage) SignedURL

func (s *LocalStorage) SignedURL(ctx context.Context, path string, opts ...SignedURLOption) (string, error)

SignedURL returns a signed URL (not supported for local storage).

func (*LocalStorage) Stat

func (s *LocalStorage) Stat(ctx context.Context, path string) (*FileInfo, error)

Stat returns file information.

func (*LocalStorage) URL

func (s *LocalStorage) URL(ctx context.Context, path string) (string, error)

URL returns a public URL for the file.

type MemoryStorage

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

MemoryStorage implements Storage with in-memory storage for testing.

func NewMemoryStorage

func NewMemoryStorage() *MemoryStorage

NewMemoryStorage creates a new in-memory storage.

func (*MemoryStorage) Clear

func (s *MemoryStorage) Clear()

Clear removes all files from memory.

func (*MemoryStorage) Close

func (s *MemoryStorage) Close() error

Close is a no-op for memory storage.

func (*MemoryStorage) Copy

func (s *MemoryStorage) Copy(ctx context.Context, src, dst string) error

Copy copies a file in memory.

func (*MemoryStorage) Delete

func (s *MemoryStorage) Delete(ctx context.Context, path string) error

Delete removes a file from memory.

func (*MemoryStorage) Exists

func (s *MemoryStorage) Exists(ctx context.Context, path string) (bool, error)

Exists checks if a file exists in memory.

func (*MemoryStorage) Get

func (s *MemoryStorage) Get(ctx context.Context, path string) (io.ReadCloser, error)

Get retrieves content from memory.

func (*MemoryStorage) GetBytes

func (s *MemoryStorage) GetBytes(path string) ([]byte, error)

GetBytes returns the raw bytes of a file (useful for testing).

func (*MemoryStorage) List

func (s *MemoryStorage) List(ctx context.Context, prefix string, opts ...ListOption) (*ListResult, error)

List returns files matching the prefix.

func (*MemoryStorage) Move

func (s *MemoryStorage) Move(ctx context.Context, src, dst string) error

Move moves a file in memory atomically.

func (*MemoryStorage) Put

func (s *MemoryStorage) Put(ctx context.Context, path string, reader io.Reader, opts ...PutOption) (*FileInfo, error)

Put uploads content to memory.

func (*MemoryStorage) SignedURL

func (s *MemoryStorage) SignedURL(ctx context.Context, path string, opts ...SignedURLOption) (string, error)

SignedURL returns a signed URL (not supported for memory storage).

func (*MemoryStorage) Size

func (s *MemoryStorage) Size() int

Size returns the number of files in memory.

func (*MemoryStorage) Stat

func (s *MemoryStorage) Stat(ctx context.Context, path string) (*FileInfo, error)

Stat returns file information.

func (*MemoryStorage) TotalBytes

func (s *MemoryStorage) TotalBytes() int64

TotalBytes returns the total size of all files in memory.

func (*MemoryStorage) URL

func (s *MemoryStorage) URL(ctx context.Context, path string) (string, error)

URL returns a URL for the file.

func (*MemoryStorage) WithBaseURL

func (s *MemoryStorage) WithBaseURL(url string) *MemoryStorage

WithBaseURL sets the base URL for the memory storage.

type PutOption

type PutOption func(*PutOptions)

PutOption is a function that modifies PutOptions.

func WithACL

func WithACL(acl string) PutOption

WithACL sets the access control.

func WithCacheControl

func WithCacheControl(cacheControl string) PutOption

WithCacheControl sets the Cache-Control header.

func WithContentType

func WithContentType(contentType string) PutOption

WithContentType sets the content type.

func WithMetadata

func WithMetadata(metadata map[string]string) PutOption

WithMetadata sets custom metadata.

func WithOverwrite

func WithOverwrite(overwrite bool) PutOption

WithOverwrite allows overwriting existing files.

type PutOptions

type PutOptions struct {
	ContentType  string            // MIME type (auto-detected if empty)
	Metadata     map[string]string // Custom metadata
	CacheControl string            // Cache-Control header
	ACL          string            // Access control (e.g., "public-read")
	Overwrite    bool              // Allow overwriting existing files
}

PutOptions configures upload behavior.

func ApplyPutOptions

func ApplyPutOptions(opts []PutOption) *PutOptions

ApplyPutOptions applies PutOption functions to PutOptions.

type SignedURLOption

type SignedURLOption func(*SignedURLOptions)

SignedURLOption is a function that modifies SignedURLOptions.

func WithExpires

func WithExpires(expires time.Duration) SignedURLOption

WithExpires sets the URL expiration time.

func WithHeaders

func WithHeaders(headers map[string]string) SignedURLOption

WithHeaders sets additional headers for signed URLs.

func WithMethod

func WithMethod(method string) SignedURLOption

WithMethod sets the HTTP method for the signed URL.

func WithSignedContentType

func WithSignedContentType(contentType string) SignedURLOption

WithSignedContentType sets the content type for PUT signed URLs.

type SignedURLOptions

type SignedURLOptions struct {
	Expires     time.Duration     // URL expiration time
	Method      string            // HTTP method (GET, PUT)
	ContentType string            // Content-Type for PUT requests
	Headers     map[string]string // Additional headers
}

SignedURLOptions configures signed URL generation.

func ApplySignedURLOptions

func ApplySignedURLOptions(opts []SignedURLOption) *SignedURLOptions

ApplySignedURLOptions applies SignedURLOption functions to SignedURLOptions.

type Storage

type Storage interface {
	// Put uploads content to the specified path.
	Put(ctx context.Context, path string, reader io.Reader, opts ...PutOption) (*FileInfo, error)

	// Get retrieves content from the specified path.
	Get(ctx context.Context, path string) (io.ReadCloser, error)

	// Delete removes the file at the specified path.
	Delete(ctx context.Context, path string) error

	// Exists checks if a file exists at the specified path.
	Exists(ctx context.Context, path string) (bool, error)

	// Stat returns file information without downloading content.
	Stat(ctx context.Context, path string) (*FileInfo, error)

	// List returns files matching the prefix.
	List(ctx context.Context, prefix string, opts ...ListOption) (*ListResult, error)

	// Copy copies a file from src to dst.
	Copy(ctx context.Context, src, dst string) error

	// Move moves a file from src to dst.
	Move(ctx context.Context, src, dst string) error

	// URL returns a public URL for the file (if supported).
	URL(ctx context.Context, path string) (string, error)

	// SignedURL returns a pre-signed URL for temporary access.
	SignedURL(ctx context.Context, path string, opts ...SignedURLOption) (string, error)

	// Close releases any resources held by the storage backend.
	Close() error
}

Storage defines the interface for storage backends.

Directories

Path Synopsis
examples
basic command
Example: basic demonstrates core objstore operations using local filesystem storage.
Example: basic demonstrates core objstore operations using local filesystem storage.
helpers command
Example: helpers demonstrates objstore helper functions using in-memory storage.
Example: helpers demonstrates objstore helper functions using in-memory storage.
switching-backends command
Example: switching-backends demonstrates how to swap storage backends using the unified objstore.Storage interface.
Example: switching-backends demonstrates how to swap storage backends using the unified objstore.Storage interface.

Jump to

Keyboard shortcuts

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