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: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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
⌂ 换网址