spaces

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package spaces provides an S3-compatible object storage client for DigitalOcean Spaces (or any S3-compatible endpoint) with presigned upload/download URLs, metadata lookup, ranged reads, and deletion.

All object keys are namespaced under the configured KeyPrefix and validated before use: keys containing "..", ".", or empty path segments, leading slashes, or control characters are rejected with ErrInvalidKey so callers cannot escape the prefix namespace (e.g. a per-tenant prefix).

Basic usage:

client, err := spaces.New(ctx, spaces.Options{
    Region:    "nyc3",
    Endpoint:  "https://nyc3.digitaloceanspaces.com",
    Bucket:    "my-bucket",
    KeyPrefix: "tenant-42/",
    AccessKey: accessKey,
    SecretKey: secretKey,
})
if err != nil {
    return err
}

url, err := client.PresignPut(ctx, "avatars/user.png", "image/png", size, 15*time.Minute)

Presign TTLs must be positive and at most MaxPresignTTL (7 days, the S3 protocol limit).

Index

Constants

View Source
const MaxPresignTTL = 7 * 24 * time.Hour

Variables

View Source
var (
	ErrNotFound       = errors.New("object not found")
	ErrInvalidKey     = errors.New("spaces: invalid object key")
	ErrInvalidTTL     = errors.New("spaces: presign TTL must be positive and at most 7 days")
	ErrInvalidOptions = errors.New("spaces: invalid options")
)

Functions

This section is empty.

Types

type Client

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

func New

func New(ctx context.Context, opts Options) (*Client, error)

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, logicalKey string) error

func (*Client) Head

func (c *Client) Head(ctx context.Context, logicalKey string) (*HeadResult, error)

func (*Client) PresignGet

func (c *Client) PresignGet(ctx context.Context, logicalKey string, ttl time.Duration) (string, error)

func (*Client) PresignPut

func (c *Client) PresignPut(
	ctx context.Context,
	logicalKey, contentType string,
	contentLength int64,
	ttl time.Duration,
) (string, error)

func (*Client) RangeGet

func (c *Client) RangeGet(ctx context.Context, logicalKey string, maxBytes int64) ([]byte, error)

type HeadResult

type HeadResult struct {
	ContentLength int64
	ContentType   string
}

type Options

type Options struct {
	Region    string
	Endpoint  string
	Bucket    string
	KeyPrefix string // empty, or ends with "/"
	AccessKey string
	SecretKey string
}

Jump to

Keyboard shortcuts

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