storage

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package storage provides artifact storage backends for the proxy cache.

Storage backends are accessed via gocloud.dev/blob URLs:

  • file:///path/to/dir - Local filesystem storage
  • s3://bucket-name - Amazon S3
  • s3://bucket?endpoint=http://localhost:9000 - S3-compatible (MinIO)

Use OpenBucket to create a storage backend from a URL.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("artifact not found")

	// ErrSignedURLUnsupported is returned by SignedURL when the backend
	// cannot generate presigned URLs (e.g. local filesystem).
	ErrSignedURLUnsupported = errors.New("signed URLs not supported by storage backend")
)

Functions

func ArtifactPath

func ArtifactPath(ecosystem, namespace, name, version, filename string) string

ArtifactPath builds a storage path for an artifact. Format: {ecosystem}/{namespace}/{name}/{version}/{filename} For packages without namespace: {ecosystem}/{name}/{version}/{filename}

Types

type Blob

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

Blob implements Storage using gocloud.dev/blob. Supports local filesystem (file://) and S3 (s3://) URLs.

func OpenBucket

func OpenBucket(ctx context.Context, urlStr string) (*Blob, error)

OpenBucket opens a blob bucket from a URL.

Supported URL schemes:

  • file:///path/to/dir - Local filesystem storage
  • s3://bucket-name - Amazon S3 (uses AWS_* environment variables)
  • s3://bucket-name?region=us-east-1&endpoint=http://localhost:9000 - S3-compatible (MinIO, etc.)

For local filesystem, the directory is created if it doesn't exist.

func (*Blob) Close

func (b *Blob) Close() error

func (*Blob) Delete

func (b *Blob) Delete(ctx context.Context, path string) error

func (*Blob) Exists

func (b *Blob) Exists(ctx context.Context, path string) (bool, error)

func (*Blob) Open

func (b *Blob) Open(ctx context.Context, path string) (io.ReadCloser, error)

func (*Blob) SignedURL

func (b *Blob) SignedURL(ctx context.Context, path string, expiry time.Duration) (string, error)

func (*Blob) Size

func (b *Blob) Size(ctx context.Context, path string) (int64, error)

func (*Blob) Store

func (b *Blob) Store(ctx context.Context, path string, r io.Reader) (int64, string, error)

func (*Blob) URL

func (b *Blob) URL() string

func (*Blob) UsedSpace

func (b *Blob) UsedSpace(ctx context.Context) (int64, error)

type Filesystem

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

Filesystem implements Storage using the local filesystem.

func NewFilesystem

func NewFilesystem(root string) (*Filesystem, error)

NewFilesystem creates a new filesystem storage rooted at the given directory. The directory will be created if it does not exist.

func (*Filesystem) Close

func (fs *Filesystem) Close() error

func (*Filesystem) Delete

func (fs *Filesystem) Delete(ctx context.Context, path string) error

func (*Filesystem) Exists

func (fs *Filesystem) Exists(ctx context.Context, path string) (bool, error)

func (*Filesystem) FullPath

func (fs *Filesystem) FullPath(path string) (string, error)

FullPath returns the full filesystem path for a storage path. Useful for serving files directly or debugging. Returns an error if the resulting path would escape the storage root.

func (*Filesystem) Open

func (fs *Filesystem) Open(ctx context.Context, path string) (io.ReadCloser, error)

func (*Filesystem) Root

func (fs *Filesystem) Root() string

Root returns the root directory of the storage.

func (*Filesystem) SignedURL

func (fs *Filesystem) SignedURL(_ context.Context, _ string, _ time.Duration) (string, error)

func (*Filesystem) Size

func (fs *Filesystem) Size(ctx context.Context, path string) (int64, error)

func (*Filesystem) Store

func (fs *Filesystem) Store(ctx context.Context, path string, r io.Reader) (int64, string, error)

func (*Filesystem) URL

func (fs *Filesystem) URL() string

func (*Filesystem) UsedSpace

func (fs *Filesystem) UsedSpace(ctx context.Context) (int64, error)

type HashingReader

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

HashingReader wraps a reader and computes SHA256 hash as content is read.

func NewHashingReader

func NewHashingReader(r io.Reader) *HashingReader

func (*HashingReader) Read

func (hr *HashingReader) Read(p []byte) (n int, err error)

func (*HashingReader) Size

func (hr *HashingReader) Size() int64

func (*HashingReader) Sum

func (hr *HashingReader) Sum() string

type Storage

type Storage interface {
	// Store writes content from r to the given path.
	// Returns the number of bytes written and the SHA256 hash of the content.
	Store(ctx context.Context, path string, r io.Reader) (size int64, hash string, err error)

	// Open returns a reader for the content at path.
	// The caller must close the reader when done.
	// Returns ErrNotFound if the path does not exist.
	Open(ctx context.Context, path string) (io.ReadCloser, error)

	// Exists returns true if content exists at path.
	Exists(ctx context.Context, path string) (bool, error)

	// Delete removes the content at path.
	// Returns nil if the path does not exist.
	Delete(ctx context.Context, path string) error

	// Size returns the size in bytes of content at path.
	// Returns ErrNotFound if the path does not exist.
	Size(ctx context.Context, path string) (int64, error)

	// SignedURL returns a presigned URL granting time-limited GET access to path.
	// Returns ErrSignedURLUnsupported if the backend cannot generate presigned URLs.
	SignedURL(ctx context.Context, path string, expiry time.Duration) (string, error)

	// UsedSpace returns the total bytes used by all stored content.
	UsedSpace(ctx context.Context) (int64, error)

	// URL returns the storage backend URL (e.g. "file:///path" or "s3://bucket").
	URL() string

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

Storage defines the interface for artifact storage backends.

Jump to

Keyboard shortcuts

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