s3

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 15 Imported by: 0 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

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client reads and writes objects in one bucket.

func Default

func Default(bucket string) (*Client, error)

Default builds a client with a 5 second timeout and 3 total attempts.

func New

func New(bucket string, timeout time.Duration, maxRetryAttempts int) (*Client, error)

New builds a client for bucket. timeout is the deadline for each call. maxRetryAttempts is passed to the SDK as MaxAttempts, which counts the first attempt.

func (*Client) CheckBucket added in v0.15.0

func (c *Client) CheckBucket(ctx context.Context) error

CheckBucket confirms the bucket exists and the caller can reach it. A missing bucket wraps ErrNotFound.

func (*Client) Get

func (c *Client) Get(ctx context.Context, key string) (*GetResult, error)

Get returns the object at key. A missing key wraps ErrNotFound. The caller closes Body. Closing it ends the Get deadline.

func (*Client) Head added in v0.15.0

func (c *Client) Head(ctx context.Context, key string) (*HeadResult, error)

Head returns the metadata for key without downloading its body. A missing key wraps ErrNotFound.

S3 answers 404 for a missing bucket as well as a missing key, so a missing bucket also wraps ErrNotFound here. Call CheckBucket first when the two must be told apart.

func (*Client) List

func (c *Client) List(ctx context.Context, prefix, continuationToken string) (*ListResult, error)

List returns one page of objects under prefix. An empty prefix lists the bucket. Pass the previous NextContinuationToken to read the next page. An empty page is success.

func (*Client) Put

func (c *Client) Put(ctx context.Context, key string, body io.Reader, contentType string, opts ...PutOption) error

Put writes body to key, replacing any existing object. A seekable body lets the SDK set the content length. Pass WithMetadata to store user metadata alongside the object.

type GetResult

type GetResult struct {
	Body         io.ReadCloser
	ContentType  string
	Size         int64
	LastModified time.Time
	Metadata     map[string]string
}

GetResult is the body and metadata for one key. The caller closes Body. The Get deadline stays in effect until Body is closed. Metadata holds the user metadata set on the object, keyed without the x-amz-meta- prefix.

type HeadResult added in v0.15.0

type HeadResult struct {
	ContentType  string
	Size         int64
	LastModified time.Time
	Metadata     map[string]string
}

HeadResult is the metadata for one key, read without its body. Metadata holds the user metadata set on the object, keyed without the x-amz-meta- prefix.

type ListResult

type ListResult struct {
	Objects               []ObjectInfo
	NextContinuationToken string
}

ListResult is one page of objects. NextContinuationToken is empty on the last page.

type ObjectInfo

type ObjectInfo struct {
	Key          string
	Size         int64
	LastModified time.Time
}

ObjectInfo is one key returned by List.

type PutOption added in v0.15.0

type PutOption func(*sdks3.PutObjectInput)

PutOption sets an optional field on a Put.

func WithMetadata added in v0.15.0

func WithMetadata(metadata map[string]string) PutOption

WithMetadata stores metadata as the object's user metadata, served back as x-amz-meta-<key> headers and returned by Get and Head. S3 lowercases the keys. It replaces any metadata the object had before, as Put replaces the whole object.

Jump to

Keyboard shortcuts

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