Documentation ¶
Index ¶
- Variables
- type ModulesIntegration
- type PushFunc
- type Registry
- func (r *Registry) DatabaseName() string
- func (r *Registry) Get(key string) (record.Record, error)
- func (r *Registry) GetRegistrationKeys() []string
- func (r *Registry) InjectAsDatabase(name string) error
- func (r *Registry) Put(m record.Record) (record.Record, error)
- func (r *Registry) Query(q *query.Query, local, internal bool) (*iterator.Iterator, error)
- func (r *Registry) Register(keyOrPrefix string, p ValueProvider) (PushFunc, error)
- type SimpleValueGetterFunc
- type SimpleValueSetterFunc
- type ValueProvider
Constants ¶
This section is empty.
Variables ¶
var ( // ErrReadOnly should be returned from ValueProvider.Set if a // runtime record is considered read-only. ErrReadOnly = errors.New("runtime record is read-only") // ErrWriteOnly should be returned from ValueProvider.Get if // a runtime record is considered write-only. ErrWriteOnly = errors.New("runtime record is write-only") )
var ( // ErrKeyTaken is returned when trying to register // a value provider at database key or prefix that // is already occupied by another provider. ErrKeyTaken = errors.New("runtime key or prefix already used") // ErrKeyUnmanaged is returned when a Put operation // on an unmanaged key is performed. ErrKeyUnmanaged = errors.New("runtime key not managed by any provider") // ErrInjected is returned by Registry.InjectAsDatabase // if the registry has already been injected. ErrInjected = errors.New("registry already injected") )
var DefaultRegistry = NewRegistry()
DefaultRegistry is the default registry that is used by the module-level API.
Functions ¶
This section is empty.
Types ¶
type ModulesIntegration ¶ added in v0.10.0
type ModulesIntegration struct{}
ModulesIntegration provides integration with the modules system.
func (*ModulesIntegration) Get ¶ added in v0.10.0
func (mi *ModulesIntegration) Get(keyOrPrefix string) ([]record.Record, error)
Get should return one or more records that match keyOrPrefix. keyOrPrefix is guaranteed to be at least the prefix used to register the ValueProvider.
type PushFunc ¶
PushFunc is returned when registering a new value provider and can be used to inform the database system about the availability of a new runtime record value. Similar to database.Controller.PushUpdate, the caller must hold the lock for each record passed to PushFunc.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry keeps track of registered runtime value providers and exposes them via an injected database. Users normally just need to use the defaul registry provided by this package but may consider creating a dedicated runtime registry on their own. Registry uses a radix tree for value providers and their chosen database key/prefix.
func (*Registry) DatabaseName ¶
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 (*Registry) Get ¶
Get returns the runtime value that is identified by key. It implements the storage.Interface.
func (*Registry) GetRegistrationKeys ¶
GetRegistrationKeys returns a list of all provider registration keys or prefixes.
func (*Registry) InjectAsDatabase ¶
InjectAsDatabase injects the registry as the storage database for name.
func (*Registry) Put ¶
Put stores the record m in the runtime database. Note that ErrReadOnly is returned if there's no value provider responsible for m.Key().
func (*Registry) Query ¶
Query performs a query on the runtime registry returning all records across all value providers that match q. Query implements the storage.Storage interface.
func (*Registry) Register ¶
func (r *Registry) Register(keyOrPrefix string, p ValueProvider) (PushFunc, error)
Register registers a new value provider p under keyOrPrefix. The returned PushFunc can be used to send update notitifcations to database subscribers. Note that keyOrPrefix must end in '/' to be accepted as a prefix.
type SimpleValueGetterFunc ¶
SimpleValueGetterFunc is a convenience type for implementing a read-only value provider.
type SimpleValueSetterFunc ¶
SimpleValueSetterFunc is a convenience type for implementing a write-only value provider.
type ValueProvider ¶
type ValueProvider interface { // Set is called when the value is set from outside. // If the runtime value is considered read-only ErrReadOnly // should be returned. It is guaranteed that the key of // the record passed to Set is prefixed with the key used // to register the value provider. Set(record.Record) (record.Record, error) // Get should return one or more records that match keyOrPrefix. // keyOrPrefix is guaranteed to be at least the prefix used to // register the ValueProvider. Get(keyOrPrefix string) ([]record.Record, error) }
ValueProvider provides access to a runtime-computed database record.
func ProvideRecord ¶
func ProvideRecord(r record.Record) ValueProvider
ProvideRecord returns a ValueProvider the exposes read-only access to r. Users of ProvideRecord need to ensure the lock the whole record before performing modifications on it.
Example:
type MyValue struct { record.Base Value string } r := new(MyValue) pushUpdate, _ := runtime.Register("my/key", ProvideRecord(r)) r.Lock() r.Value = "foobar" pushUpdate(r) r.Unlock()
func TraceProvider ¶
func TraceProvider(vp ValueProvider) ValueProvider
TraceProvider returns a new ValueProvider that wraps vp but traces all Set and Get methods calls.