Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrEmpty = errors.New("MultiStorage has no underlying stores")
var ErrUnexpectedMultipleAnswers = errors.New("MultiStorage: results returned were not the same")
Functions ¶
This section is empty.
Types ¶
type Loader ¶
type Loader func(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(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.
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 immidately 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