storage

package
v0.0.0-...-e9f7c1f Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: Apache-2.0 Imports: 13 Imported by: 2

Documentation

Overview

Filesystem storage backend for Nixery.

Google Cloud Storage backend for Nixery.

Package storage implements an interface that can be implemented by storage backends, such as Google Cloud Storage or the local filesystem.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	// Name returns the name of the storage backend, for use in
	// log messages and such.
	Name() string

	// Persist provides a user-supplied function with a writer
	// that stores data in the storage backend.
	//
	// It needs to return the SHA256 hash of the data written as
	// well as the total number of bytes, as those are required
	// for the image manifest.
	Persist(ctx context.Context, path, contentType string, f Persister) (string, int64, error)

	// Fetch retrieves data from the storage backend.
	Fetch(ctx context.Context, path string) (io.ReadCloser, error)

	// Move renames a path inside the storage backend. This is
	// used for staging uploads while calculating their hashes.
	Move(ctx context.Context, old, new string) error

	// Serve provides a handler function to serve HTTP requests
	// for objects in the storage backend.
	Serve(digest string, r *http.Request, w http.ResponseWriter) error
}

type FSBackend

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

func NewFSBackend

func NewFSBackend() (*FSBackend, error)

func (*FSBackend) Fetch

func (b *FSBackend) Fetch(ctx context.Context, key string) (io.ReadCloser, error)

func (*FSBackend) Move

func (b *FSBackend) Move(ctx context.Context, old, new string) error

func (*FSBackend) Name

func (b *FSBackend) Name() string

func (*FSBackend) Persist

func (b *FSBackend) Persist(ctx context.Context, key, contentType string, f Persister) (string, int64, error)

func (*FSBackend) Serve

func (b *FSBackend) Serve(digest string, r *http.Request, w http.ResponseWriter) error

type GCSBackend

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

func NewGCSBackend

func NewGCSBackend() (*GCSBackend, error)

Constructs a new GCS bucket backend based on the configured environment variables.

func (*GCSBackend) Fetch

func (b *GCSBackend) Fetch(ctx context.Context, path string) (io.ReadCloser, error)

func (*GCSBackend) Move

func (b *GCSBackend) Move(ctx context.Context, old, new string) error

renameObject renames an object in the specified Cloud Storage bucket.

The Go API for Cloud Storage does not support renaming objects, but the HTTP API does. The code below makes the relevant call manually.

func (*GCSBackend) Name

func (b *GCSBackend) Name() string

func (*GCSBackend) Persist

func (b *GCSBackend) Persist(ctx context.Context, path, contentType string, f Persister) (string, int64, error)

func (*GCSBackend) Serve

func (b *GCSBackend) Serve(digest string, r *http.Request, w http.ResponseWriter) error

type Persister

type Persister = func(io.Writer) (string, int64, error)

Jump to

Keyboard shortcuts

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