Documentation
¶
Overview ¶
Package s3 provides an S3 integration block with a clean object storage API.
Index ¶
- type Block
- func (b *Block) DeleteObject(ctx context.Context, key string) error
- func (b *Block) GetObject(ctx context.Context, key string) (io.ReadCloser, ObjectMetadata, error)
- func (b *Block) Init(ctx context.Context) error
- func (b *Block) ListObjects(ctx context.Context, prefix string) ([]ObjectInfo, error)
- func (b *Block) Name() string
- func (b *Block) PresignGetURL(ctx context.Context, key string, expiry time.Duration) (string, error)
- func (b *Block) PutObject(ctx context.Context, key string, body io.Reader, opts ...PutOption) error
- func (b *Block) Shutdown(_ context.Context) error
- type ObjectInfo
- type ObjectMetadata
- type Option
- type PutOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Block ¶
type Block struct {
// contains filtered or unexported fields
}
Block is an S3 integration block that exposes a clean object storage API.
func New ¶
New creates a new S3 Block.
block := s3.New("assets",
s3.WithRegion("us-east-1"),
s3.WithBucket("my-assets-bucket"),
s3.WithKeyPrefix("uploads/"),
)
func (*Block) DeleteObject ¶
DeleteObject removes a single object by key.
func (*Block) GetObject ¶
func (b *Block) GetObject(ctx context.Context, key string) (io.ReadCloser, ObjectMetadata, error)
GetObject retrieves an object by key. The caller is responsible for closing the returned ReadCloser.
func (*Block) ListObjects ¶
ListObjects returns all objects whose key starts with prefix (relative to the block's configured key prefix). Pagination is handled internally.
func (*Block) PresignGetURL ¶
func (b *Block) PresignGetURL(ctx context.Context, key string, expiry time.Duration) (string, error)
PresignGetURL generates a pre-signed GET URL that grants temporary access to an object without requiring AWS credentials.
type ObjectInfo ¶
ObjectInfo represents a summary of an object returned by ListObjects.
type ObjectMetadata ¶
type ObjectMetadata struct {
ContentType string
ContentLength int64
ETag string
LastModified time.Time
}
ObjectMetadata holds selected metadata returned alongside a GetObject response.
type Option ¶
type Option func(*blockConfig)
Option configures an S3 Block.
func WithAWSConfig ¶
WithAWSConfig injects a pre-built aws.Config.
func WithEndpoint ¶
WithEndpoint overrides the S3 endpoint (e.g. "http://localhost:4566" for LocalStack). Automatically enables path-style addressing.
func WithKeyPrefix ¶
WithKeyPrefix sets an optional prefix prepended to every object key. Useful for namespacing objects within a shared bucket.
func WithPathStyle ¶
func WithPathStyle() Option
WithPathStyle enables S3 path-style addressing. Required for MinIO and similar S3-compatible services.
func WithProfile ¶
WithProfile selects a named AWS credentials profile.
type PutOption ¶
type PutOption func(*putOptions)
PutOption configures a PutObject call.
func WithContentType ¶
WithContentType sets the Content-Type header for uploaded objects.
func WithMetadata ¶
WithMetadata attaches custom metadata key-value pairs to an uploaded object.