package s3

import "golazy.dev/lazystorage/s3"

Package s3 provides an S3-compatible lazystorage backend.

Types

type Option

Option configures Storage.

type Option func(*Storage)
func WithBucket

WithBucket sets the bucket name.

func WithBucket(bucket string) Option
func WithCredentials

WithCredentials sets the access key pair used for signed S3 requests.

func WithCredentials(accessKeyID, secretAccessKey string) Option
func WithEndpoint

WithEndpoint sets the S3 API endpoint.

func WithEndpoint(endpoint string) Option
func WithHTTPClient

WithHTTPClient sets the HTTP client used for S3 requests.

func WithHTTPClient(client *http.Client) Option
func WithPublicBaseURL

WithPublicBaseURL sets the URL prefix returned by URL.

For SeaweedFS deployments this is usually an ingress path that rewrites to the filer, for example https://example.com/assets.

func WithPublicBaseURL(baseURL string) Option
func WithRegion

WithRegion sets the SigV4 region. S3-compatible stores commonly accept us-east-1 even when they are not hosted in AWS.

func WithRegion(region string) Option
func WithSessionToken

WithSessionToken sets the optional session token for temporary credentials.

func WithSessionToken(token string) Option

type Storage

Storage stores objects in an S3-compatible bucket.

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

New creates an S3-compatible storage.

func New(options ...Option) *Storage
func (s *Storage) Delete

Delete removes key.

func (s *Storage) Delete(ctx context.Context, key string, options ...any) ([]any, error)
func (s *Storage) EnsureBucket

EnsureBucket creates the configured bucket if it does not already exist.

func (s *Storage) EnsureBucket(ctx context.Context) error
func (s *Storage) List

List lists object metadata below prefix.

func (s *Storage) List(ctx context.Context, prefix string, options ...any) (lazystorage.Iterator, []any, error)
func (s *Storage) Open

Open opens key for reading.

func (s *Storage) Open(ctx context.Context, key string, options ...any) (lazystorage.File, []any, error)
func (s *Storage) Put

Put writes key to the bucket.

func (s *Storage) Put(ctx context.Context, key string, body io.Reader, options ...any) (lazystorage.Info, []any, error)
func (s *Storage) URL

URL returns the configured public mount URL for key.

func (s *Storage) URL(ctx context.Context, key string, options ...any) (lazystorage.URL, []any, error)
func (s *Storage) Watch

Watch polls the bucket and emits put/delete events for key changes.

func (s *Storage) Watch(ctx context.Context, prefix string, options ...any) (lazystorage.Events, []any, error)