Add GetMeta to database storage interface

This commit is contained in:
Daniel 2021-05-11 14:57:53 +02:00
parent 3f3786b854
commit 0061572e1b
11 changed files with 170 additions and 32 deletions

View file

@ -42,7 +42,7 @@ func (c *Controller) Injected() bool {
return c.storage.Injected()
}
// Get return the record with the given key.
// Get returns the record with the given key.
func (c *Controller) Get(key string) (record.Record, error) {
if shuttingDown.IsSet() {
return nil, ErrShuttingDown
@ -76,6 +76,28 @@ func (c *Controller) Get(key string) (record.Record, error) {
return r, nil
}
// Get returns the metadata of the record with the given key.
func (c *Controller) GetMeta(key string) (*record.Meta, error) {
if shuttingDown.IsSet() {
return nil, ErrShuttingDown
}
m, err := c.storage.GetMeta(key)
if err != nil {
// replace not found error
if err == storage.ErrNotFound {
return nil, ErrNotFound
}
return nil, err
}
if !m.CheckValidity() {
return nil, ErrNotFound
}
return m, nil
}
// Put saves a record in the database, executes any registered
// pre-put hooks and finally send an update to all subscribers.
// The record must be locked and secured from concurrent access