mirror of
https://github.com/safing/portbase
synced 2025-09-01 18:19:57 +00:00
Fix incorrect type of SimpleValue(S)(G)etter
This commit is contained in:
parent
50a10485e1
commit
511cb22759
2 changed files with 20 additions and 4 deletions
|
@ -38,7 +38,7 @@ type (
|
|||
|
||||
// SimpleValueSetterFunc is a convenience type for implementing a
|
||||
// write-only value provider.
|
||||
SimpleValueSetterFunc func(record.Record) error
|
||||
SimpleValueSetterFunc func(record.Record) (record.Record, error)
|
||||
|
||||
// SimpleValueGetterFunc is a convenience type for implementing a
|
||||
// read-only value provider.
|
||||
|
@ -46,7 +46,7 @@ type (
|
|||
)
|
||||
|
||||
// Set implements ValueProvider.Set and calls fn.
|
||||
func (fn SimpleValueSetterFunc) Set(r record.Record) error {
|
||||
func (fn SimpleValueSetterFunc) Set(r record.Record) (record.Record, error) {
|
||||
return fn(r)
|
||||
}
|
||||
|
||||
|
@ -56,11 +56,15 @@ func (SimpleValueSetterFunc) Get(_ string) ([]record.Record, error) {
|
|||
}
|
||||
|
||||
// Set implements ValueProvider.Set and returns ErrReadOnly.
|
||||
func (SimpleValueGetterFunc) Set(r record.Record) error {
|
||||
return ErrReadOnly
|
||||
func (SimpleValueGetterFunc) Set(r record.Record) (record.Record, error) {
|
||||
return nil, ErrReadOnly
|
||||
}
|
||||
|
||||
// Get implements ValueProvider.Get and calls fn.
|
||||
func (fn SimpleValueGetterFunc) Get(keyOrPrefix string) ([]record.Record, error) {
|
||||
return fn(keyOrPrefix)
|
||||
}
|
||||
|
||||
// compile time checks
|
||||
var _ ValueProvider = SimpleValueGetterFunc(nil)
|
||||
var _ ValueProvider = SimpleValueSetterFunc(nil)
|
||||
|
|
|
@ -40,6 +40,7 @@ type Registry struct {
|
|||
l sync.RWMutex
|
||||
providers *radix.Tree
|
||||
dbController *database.Controller
|
||||
dbName string
|
||||
}
|
||||
|
||||
// keyedValueProvider simply wraps a value provider with it's
|
||||
|
@ -60,6 +61,16 @@ func isPrefixKey(key string) bool {
|
|||
return strings.HasSuffix(key, "/")
|
||||
}
|
||||
|
||||
// DatabaseName returns the name of the database where the
|
||||
// registry has been injected. It returns an empty string
|
||||
// if InjectAsDatabase has not been called.
|
||||
func (r *Registry) DatabaseName() string {
|
||||
r.l.RLock()
|
||||
defer r.l.RUnlock()
|
||||
|
||||
return r.dbName
|
||||
}
|
||||
|
||||
// InjectAsDatabase injects the registry as the storage
|
||||
// database for name.
|
||||
func (r *Registry) InjectAsDatabase(name string) error {
|
||||
|
@ -75,6 +86,7 @@ func (r *Registry) InjectAsDatabase(name string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
r.dbName = name
|
||||
r.dbController = ctrl
|
||||
|
||||
return nil
|
||||
|
|
Loading…
Add table
Reference in a new issue