s3

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package s3 is a platform module: S3 compatible object storage — MinIO locally, any S3 in production — for the files of the project.

The storage API is taply's: Put into a bucket that is created on first use, with an anonymous read policy when the files are served publicly, and Delete. On top of it come streaming uploads, reads and signed links.

Index

Constants

View Source
const DefaultStartupTimeout = 15 * time.Second

DefaultStartupTimeout is the StartupTimeout Load uses when S3_STARTUP_TIMEOUT is unset.

Variables

View Source
var ErrNotFound = errors.New("s3: object not found")

ErrNotFound is returned for an object that does not exist.

Functions

This section is empty.

Types

type Config

type Config struct {
	Endpoint  string // host:port, without the scheme
	AccessKey string
	SecretKey string
	UseSSL    bool
	Region    string

	// PublicURL is where public buckets are served from, for example the /storage/ path
	// of the nginx in front of the service. Empty means links point at the endpoint.
	PublicURL string

	// StartupTimeout is how long the start keeps retrying a storage that does not
	// answer: a storage that comes up a moment after the instance, as in a rolling
	// deploy, does not stop the start. Each attempt waits up to 5 seconds, pauses grow
	// from 250ms to 2s, and no attempt starts after StartupTimeout. A refusal of the
	// storage itself, such as wrong keys, stops the start at once. Zero is a single
	// attempt, the behaviour before v0.11.2; Load sets 15 seconds.
	StartupTimeout time.Duration

	// Optional starts the service even when the storage does not answer: the start
	// logs a warning instead of failing, /health reports s3 as degraded with status
	// 200 while it is unreachable, and file operations return its errors. For a
	// service whose files are a side feature.
	Optional bool
}

Config holds module settings. Load fills it from the environment; the platform generator writes the Load call into the project's config.gen.go.

func Load

func Load(l *confx.Loader) Config

Load reads the module settings from environment variables. The names are taply's.

type Module

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

Module implements platform.Module.

func New

func New(cfg Config) *Module

New creates the module from ready settings.

func (*Module) Health

func (m *Module) Health(ctx context.Context) error

Health checks that the storage answers and accepts the keys. With Optional a failure is reported as degraded rather than failed.

func (*Module) Init

func (m *Module) Init(ctx context.Context, app *platform.App) error

Init connects to the storage and checks that it answers, so a wrong address or key stops the start instead of the first upload. A storage that does not answer yet is retried within StartupTimeout; with Optional the start goes on without it.

func (*Module) Name

func (m *Module) Name() string

type Storage

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

Storage stores files in buckets.

func From

func From(app *platform.App) *Storage

From returns the storage from the container.

func (*Storage) Client

func (s *Storage) Client() *minio.Client

Client returns the MinIO client for what Storage does not cover.

func (*Storage) Delete

func (s *Storage) Delete(ctx context.Context, bucket, objectName string) error

Delete removes an object. Removing an object that does not exist is not an error.

func (*Storage) Get

func (s *Storage) Get(ctx context.Context, bucket, objectPath string) (io.ReadCloser, error)

Get opens an object for reading. ErrNotFound is returned when it does not exist.

func (*Storage) PublicURL

func (s *Storage) PublicURL(bucket, objectPath string) string

PublicURL returns the link to an object of a public bucket.

func (*Storage) Put

func (s *Storage) Put(ctx context.Context, bucket string, anonymousRead bool, objectPath, contentType string, b []byte) (string, error)

Put stores an object and returns its path. The bucket is created on first use; with anonymousRead a new bucket gets a public read policy. An existing bucket keeps the policy it has, so an operator who tightened it by hand is not overruled.

func (*Storage) PutStream

func (s *Storage) PutStream(ctx context.Context, bucket string, anonymousRead bool, objectPath, contentType string, r io.Reader, size int64) (string, error)

PutStream stores an object read from r, for files too large to hold in memory. A negative size streams an object of unknown length in parts.

func (*Storage) SignedURL

func (s *Storage) SignedURL(ctx context.Context, bucket, objectPath string, ttl time.Duration) (string, error)

SignedURL returns a link to a private object that works for ttl.

Jump to

Keyboard shortcuts

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