multistorage

package
v0.0.0-...-8bfd7db Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmpty = errors.New("MultiStorage has no underlying stores")
View Source
var ErrUnexpectedMultipleAnswers = errors.New("MultiStorage: results returned were not the same")

Functions

This section is empty.

Types

type Loader

type Loader func(ctx context.Context, short string, stores []storage.NamedStorage) (string, error)

Loaders are expected to process the slice of stores and return the result of Load(short) from one of them. Should return ErrEmpty if stores is empty

type MultiStorage

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

MultiStorage is a storage.NamedStorage that will allow you to interact with multiple underlying storage.NamedStorages.

func New

func New(stores []storage.NamedStorage, opts ...MultiStorageOption) (*MultiStorage, error)

func Simple

func Simple(stores ...storage.NamedStorage) (*MultiStorage, error)

func (*MultiStorage) Load

func (s *MultiStorage) Load(ctx context.Context, short string) (string, error)

Load with a basic MultiStorage will query the underlying storages (in order) returning when either a response or error is encountered, only returning an ErrShortNotSet when all underlying storages have been exhausted.

func (*MultiStorage) SaveName

func (s *MultiStorage) SaveName(ctx context.Context, short string, long string) error

SaveName will return the first successful insure that all

type MultiStorageOption

type MultiStorageOption func(*MultiStorage) error

MultiStorageOptions allows you to to configure out the MultiStorage will behave. For example should it Save changes to all underlying packages, or just the first one.

func LoadCompareAllResults

func LoadCompareAllResults() MultiStorageOption

LoadCompareAll causes the MultiStorage to try to load the short from all of the underlying stores and then compares them all for equality before returning. If they are not all equal it will return an error

func LoadFirst

func LoadFirst() MultiStorageOption

LoadFirst causes the Multistore it is configuring to return on the first store that doesn't return ErrShortNotSet

func SaveOnlyOnce

func SaveOnlyOnce() MultiStorageOption

SaveOnlyOnce causes the MultiStorage to try to save the short and url to all of the underlying stores, however it will return immediately if it has any successful saves. This will only report an error if all backends fail

func SaveToAll

func SaveToAll() MultiStorageOption

SaveToAll causes the MultiStorage to try to save the short and url to all of the underlying stores. Any/all errors will be returned together

type Saver

type Saver func(ctx context.Context, short string, url string, stores []storage.NamedStorage) error

Saver are expected to process a slice of storages and return a result of SaveName(short, url string)

Jump to

Keyboard shortcuts

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