s3

package
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2023 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package s3 implements the AWS S3 storage.

Index

Constants

View Source
const Name = "s3"

Name of the storage.

Variables

This section is empty.

Functions

func Get

func Get() storage.IStorage

Get returns a setup MongoDB, or set it up.

func RetrieveSigned added in v0.1.6

func RetrieveSigned(
	ctx context.Context,
	s storage.IStorage,
	target, bucket string,
	expire time.Duration,
) (string, error)

RetrieveSigned generates a pre-signed URL for an S3 object.

This function generates a pre-signed URL that allows anyone with the URL to retrieve the specified object from S3, even if they don't have AWS credentials. The URL is valid for the specified duration.

Parameters: - ctx: The context in which the function is called. This is used for error tracing. - s: The S3 storage interface. This must have an underlying type of *s3.S3. - bucket: The name of the S3 bucket containing the object. - key: The key (path) of the object in the S3 bucket. - expire: The duration for which the pre-signed URL is valid.

Returns: - The pre-signed URL as a string. This can be used to retrieve the object. - An error if the operation failed, or nil if the operation succeeded.

func Set

func Set(s storage.IStorage)

Set sets the storage, primarily used for testing.

Types

type Config

type Config = aws.Config

Config is the S3 configuration.

type ResponseListKeys

type ResponseListKeys struct {
	Keys []string `json:"keys"`
}

ResponseListKeys is the response from the Redis list SCAN command.

type S3

type S3 struct {
	*storage.Storage

	Bucket string `json:"bucket" validate:"required,gt=0"`

	// Client is the S3 client.
	Client *s3.S3 `json:"-" validate:"required"`

	// Config is the S3 configuration.
	Config *Config `json:"-"`

	// Target allows to set a static target. If it is empty, the target will be
	// dynamic - the one set at the operation (count, create, delete, etc) time.
	// Depending on the storage, target is a collection, a table, a bucket, etc.
	// For ElasticSearch, for example it doesn't have a concept of a database -
	// the target then is the index. Due to different cases of ElasticSearch
	// usage, the target can be static or dynamic - defined at the index time,
	// for example: log-{YYYY}-{MM}. For S3, it isn't used at all.
	Target string `json:"-" validate:"omitempty,gt=0"`
	// contains filtered or unexported fields
}

S3 storage definition.

func New

func New(ctx context.Context, bucket string, cfg *Config) (*S3, error)

New creates a new S3 storage.

func (*S3) Count

func (s *S3) Count(ctx context.Context, target string, prm *count.Count, options ...storage.Func[*count.Count]) (int64, error)

Count returns the number of items in the storage.

func (*S3) Create

func (s *S3) Create(ctx context.Context, id, target string, v any, prm *create.Create, options ...storage.Func[*create.Create]) (string, error)

Create data.

NOTE: `v` can be a file, a string, or an struct.

NOTE: Not all storages returns the ID, neither all storages requires `id` to be set. You are better off setting the ID yourself.

func (*S3) Delete

func (s *S3) Delete(ctx context.Context, id, target string, prm *delete.Delete, options ...storage.Func[*delete.Delete]) error

Delete removes data.

func (*S3) GetClient

func (s *S3) GetClient() any

GetClient returns the client.

func (*S3) List

func (s *S3) List(ctx context.Context, target string, v any, prm *list.List, options ...storage.Func[*list.List]) error

List data.

NOTE: It uses params.List.Search to query the data.

NOTE: S3 does not support the concept of "offset" and "limit" in the same way that a traditional SQL database does.

func (*S3) Retrieve

func (s *S3) Retrieve(ctx context.Context, id, target string, v any, prm *retrieve.Retrieve, options ...storage.Func[*retrieve.Retrieve]) error

Retrieve data.

func (*S3) Update

func (s *S3) Update(ctx context.Context, id, target string, v any, prm *update.Update, options ...storage.Func[*update.Update]) error

Update data.

NOTE: Not truly an update, it's an insert.

Jump to

Keyboard shortcuts

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