s3

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: Apache-2.0 Imports: 13 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

This section is empty.

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
}

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.

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.

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