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
- Variables
- type Config
- type Module
- type Storage
- func (s *Storage) Client() *minio.Client
- func (s *Storage) Delete(ctx context.Context, bucket, objectName string) error
- func (s *Storage) Get(ctx context.Context, bucket, objectPath string) (io.ReadCloser, error)
- func (s *Storage) PublicURL(bucket, objectPath string) string
- func (s *Storage) Put(ctx context.Context, bucket string, anonymousRead bool, ...) (string, error)
- func (s *Storage) PutStream(ctx context.Context, bucket string, anonymousRead bool, ...) (string, error)
- func (s *Storage) SignedURL(ctx context.Context, bucket, objectPath string, ttl time.Duration) (string, error)
Constants ¶
const DefaultStartupTimeout = 15 * time.Second
DefaultStartupTimeout is the StartupTimeout Load uses when S3_STARTUP_TIMEOUT is unset.
Variables ¶
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.
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module implements platform.Module.
func (*Module) Health ¶
Health checks that the storage answers and accepts the keys. With Optional a failure is reported as degraded rather than failed.
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage stores files in buckets.
func (*Storage) Delete ¶
Delete removes an object. Removing an object that does not exist is not an error.
func (*Storage) Get ¶
Get opens an object for reading. ErrNotFound is returned when it does not exist.
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.