s3store

package module
v0.0.0-...-87a5f95 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2025 License: MIT Imports: 19 Imported by: 1

README

s3store

GoDoc CI

Package s3store implements the blob.Store interface using Amazon S3.

Documentation

Overview

Package s3store implements the blob.StoreCloser interface on Amazon S3.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Opener

func Opener(_ context.Context, addr string) (blob.StoreCloser, error)

Opener constructs a store from an address comprising a bucket name and storage region, and an optional prefix, in the format:

[prefix@]bucket:region[?query]

Types

type KV

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

A KV implements the blob.KV interface on an S3 bucket. Since S3 does not support empty keys, access to an empty key will report blob.ErrKeyNotFound as required by the interface.

func (KV) Delete

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

Delete atomically removes a blob from the store.

func (KV) Get

func (s KV) Get(ctx context.Context, key string) ([]byte, error)

Get fetches the contents of a blob from the store.

func (KV) Has

func (s KV) Has(ctx context.Context, keys ...string) (blob.KeySet, error)

Has implements a method of the blob.KV interface.

func (KV) Len

func (s KV) Len(ctx context.Context) (int64, error)

Len reports the number of keys currently in the store.

func (KV) List

func (s KV) List(ctx context.Context, start string) iter.Seq2[string, error]

List calls f with each key in the store in lexicographic order, beginning with the first key greater than or equal to start.

func (KV) Put

func (s KV) Put(ctx context.Context, opts blob.PutOptions) error

Put writes a blob to the store.

type Options

type Options struct {
	// If set, this prefix is prepended to all keys sent to S3.
	// A trailing slash ("/") is appended if one is not already present.
	KeyPrefix string

	// If set, us these rate limits apply to requests to the store.
	ReadQPS  int
	WriteQPS int

	// Optional AWS config loader options.
	AWSConfigOptions []func(*config.LoadOptions) error
}

Options are optional settings for a KV. A nil *Options is ready for use and provides zero values for all fields.

type Store

type Store struct {
	*monitor.M[dbState, KV]
}

Store implements the blob.StoreCloser interface over an S3 bucket.

func New

func New(bucket, region string, opts *Options) (Store, error)

New creates a new Store that references the given bucket and region. If opts == nil, default options are provided as described on Options.

By default, New constructs an AWS session using ambient credentials from the environment or from a configuration file profile. To specify credentials from another source, set the [Options.AWSConfigOptions] field.

func (Store) Close

func (s Store) Close(context.Context) error

Close implements a method of blob.StoreCloser. This implementation always reports nil.

Jump to

Keyboard shortcuts

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