s3store

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 30 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

Overview

Package s3store implements objectstore.Store over the S3 API for AWS S3, Cloudflare R2, GCS (S3-compatible endpoint with HMAC keys), and MinIO.

Index

Constants

This section is empty.

Variables

View Source
var ErrLinkLocalEndpoint = errors.New(
	"bucket endpoints may not reach link-local addresses",
)

ErrLinkLocalEndpoint reports a bucket endpoint that resolved to a link-local address, where cloud metadata services answer. It is refused whatever NewStoreArgs says.

View Source
var ErrPrivateEndpoint = errors.New(
	"bucket endpoints may not reach private or loopback addresses " +
		"unless PrivateAddressesAllowed is set",
)

ErrPrivateEndpoint reports a bucket endpoint that resolved to a private, loopback, or unspecified address of a store whose NewStoreArgs.PrivateAddressesAllowed is false.

Functions

This section is empty.

Types

type NewStoreArgs

type NewStoreArgs struct {
	// Provider selects endpoint and checksum defaults. Required.
	Provider Provider
	// Endpoint is the service URL. R2 and ProviderS3 require it; GCS
	// defaults to storage.googleapis.com, and AWS to its regional endpoint.
	Endpoint string
	// Region is the bucket's region. AWS requires it; R2 uses "auto", GCS
	// defaults to "auto", and ProviderS3 to us-east-1.
	Region string
	// Bucket is the bucket's name. Required.
	Bucket string
	// Prefix scopes every key to a directory of the bucket, without leading
	// or trailing slashes; "" uses the whole bucket.
	Prefix string
	// AccessKeyID is the credential's ID (an HMAC key ID on GCS).
	AccessKeyID string
	// SecretAccessKey is the credential's secret. It signs every request
	// and is never sent.
	SecretAccessKey string
	// PathStyle puts the bucket in the URL path instead of the host name,
	// as MinIO and most self-hosted servers need.
	PathStyle bool
	// PrivateAddressesAllowed lets the store connect to private, loopback,
	// and unspecified addresses, for a bucket on a LAN or on this host.
	// Without it such an endpoint fails with ErrPrivateEndpoint, so an
	// endpoint a user typed cannot reach services inside the network.
	// Link-local and cloud metadata addresses are refused either way.
	PrivateAddressesAllowed bool
}

NewStoreArgs configures NewStore.

type Provider

type Provider string

Provider selects endpoint and checksum defaults.

const (
	// ProviderAWS is Amazon S3.
	ProviderAWS Provider = "aws"
	// ProviderR2 is Cloudflare R2.
	ProviderR2 Provider = "r2"
	// ProviderGCS is Google Cloud Storage's S3-compatible XML API, with HMAC
	// keys.
	ProviderGCS Provider = "gcs"
	// ProviderS3 is any other S3-compatible service, such as MinIO.
	ProviderS3 Provider = "s3"
)

type Store

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

Store is a bucket reached through the S3 API.

func NewStore

func NewStore(args *NewStoreArgs) (*Store, error)

NewStore builds a client for the bucket.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, key string) error

Delete removes an object. A missing key succeeds: S3 and R2 answer 204, and GCS answers 404 NoSuchKey, which is taken as success here.

func (*Store) DeleteMany

func (s *Store) DeleteMany(ctx context.Context, keys []string) ([]string, error)

DeleteMany removes keys with DeleteObjects, up to 1,000 per request. GCS's XML API has no multi-object delete, so GCS buckets delete one key at a time.

func (*Store) Get

func (s *Store) Get(ctx context.Context, key string) (io.ReadCloser, error)

Get opens an object for reading.

func (*Store) GetWithETag

func (s *Store) GetWithETag(ctx context.Context, key string) (io.ReadCloser, string, error)

GetWithETag opens an object and returns its ETag, or on GCS its generation, which is what PutIfMatch takes there.

func (*Store) List

func (s *Store) List(
	ctx context.Context,
	prefix string,
	startAfter string,
) iter.Seq2[objectstore.Object, error]

List pages through ListObjectsV2.

func (*Store) Put

func (s *Store) Put(ctx context.Context, key string, body io.ReadSeeker, size int64) error

Put uploads an object with a known size.

func (*Store) PutIfAbsent

func (s *Store) PutIfAbsent(
	ctx context.Context,
	key string,
	body io.ReadSeeker,
	size int64,
) (string, error)

PutIfAbsent uploads with If-None-Match: *, so the bucket refuses the write when the key exists.

func (*Store) PutIfMatch

func (s *Store) PutIfMatch(
	ctx context.Context,
	key string,
	body io.ReadSeeker,
	size int64,
	etag string,
) (string, error)

PutIfMatch uploads with If-Match: etag, so the bucket refuses the write when the object changed or is gone.

func (*Store) Versioning

func (s *Store) Versioning(ctx context.Context) (objectstore.Versioning, error)

Versioning reads the bucket's versioning state. R2 has no versioning API, and a provider that refuses the call reports unknown rather than failing.

Jump to

Keyboard shortcuts

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