s3storage

package module
v0.0.0-...-2f799c8 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("file not found")

Functions

This section is empty.

Types

type Config

type Config struct {
	Bucket    string
	Region    string
	Endpoint  string
	AccessKey string
	SecretKey string
}

type S3Storage

type S3Storage struct {
	Bucket string
	// contains filtered or unexported fields
}

func NewS3Storage

func NewS3Storage(ctx context.Context, cfg Config) (*S3Storage, error)

NewS3Storage creates an S3 storage client

func (*S3Storage) Delete

func (s *S3Storage) Delete(ctx context.Context, path string) error

Delete removes an object from S3.

func (*S3Storage) Download

func (s *S3Storage) Download(ctx context.Context, path string, w io.WriterAt) error

Download streams an S3 object into w.

func (*S3Storage) Exists

func (s *S3Storage) Exists(ctx context.Context, path string) (bool, error)

Exists checks if an object exists in the S3 bucket.

func (*S3Storage) Open

func (s *S3Storage) Open(ctx context.Context, path string) (io.ReadCloser, error)

Open returns a ReadCloser for the object. Caller must close it.

func (*S3Storage) Save

func (s *S3Storage) Save(ctx context.Context, path string, r io.Reader, opts ...SaveOption) error

Save uploads a file to S3. If contentType is empty, it will be auto-detected from the first 512 bytes.

type SaveOption

type SaveOption func(*SaveOptions)

func WithAutoContentType

func WithAutoContentType() SaveOption

func WithContentType

func WithContentType(ct string) SaveOption

type SaveOptions

type SaveOptions struct {
	ContentType     string
	AutoContentType bool
}

Jump to

Keyboard shortcuts

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