Documentation ¶
Index ¶
- type Storage
- func (s *Storage) Iterate(ctx context.Context, tmpl data.Object, pref data.Prefix) (data.Iterator, error)
- func (s *Storage) Load(_ context.Context, obj data.Object, key data.Key) error
- func (s *Storage) Save(_ context.Context, obj data.Object, key data.Key) error
- func (s *Storage) Search(_ context.Context, tmpl data.Object, pref data.Prefix) ([]data.Object, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage implements a data.Storage interface using a map stored in memory.
func NewStorage ¶
func NewStorage() *Storage
NewStorage creates an instance of the Storage structure and initializes the embedded map.
func (*Storage) Iterate ¶
func (s *Storage) Iterate( ctx context.Context, tmpl data.Object, pref data.Prefix, ) (data.Iterator, error)
Iterate does what Search does, but in place of the finished collection of objects an iterator will be returned that can be used to list the objects one by one. The original object is only needed as a template, other instances will be created based on it (by method Copy), but the object itself will not be changed.
func (*Storage) Load ¶
Load loads an object from the repository, using Key as a unique name (path) to find the object and Type (by calling the Instance method). The UnmarshalBinary method can be called for the object. To restore an object, you must allocate memory for it to avoid panic when working with a nil address. If the object is not found, an ErrObjectNotFound error will be returned.
func (*Storage) Save ¶
Save stores the object in a storage, using Key as the unique name (path) to save the object and Type (by calling Instance method) to share the namespace between objects. Key can be repeated for different Type values. The MarshalBinary method can be called before the object is saved.
func (*Storage) Search ¶
func (s *Storage) Search( _ context.Context, tmpl data.Object, pref data.Prefix, ) ([]data.Object, error)
Search searches for objects in the repository of a certain Type. It returns a list of found objects or ErrObjectNotFound if no objects matching the criteria were found. Prefix is used for additional filtering of objects according to their Key with partial match at the beginning of the key. If you want to get all objects Prefix can be empty. The original object is only needed as a template, other instances will be created based on it (by method Copy), but the object itself will not be changed.