Documentation ¶
Overview ¶
Package rsop facilitates source.Store registration via RegisterStore and provides access to the effective policy merged from all registered sources via PolicyFor.
Index ¶
- Variables
- type Change
- type Policy
- func (p *Policy) Close()
- func (p *Policy) Done() <-chan struct{}
- func (p *Policy) Get() *setting.Snapshot
- func (p *Policy) IsValid() bool
- func (p *Policy) RegisterChangeCallback(callback PolicyChangeCallback) (unregister func())
- func (p *Policy) Reload() (*setting.Snapshot, error)
- func (p *Policy) Scope() setting.PolicyScope
- type PolicyChange
- type PolicyChangeCallback
- type StoreRegistration
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyConsumed = errors.New("the store registration is no longer valid")
ErrAlreadyConsumed is the error returned when StoreRegistration.ReplaceStore or StoreRegistration.Unregister is called more than once.
var ErrPolicyClosed = errors.New("effective policy closed")
ErrPolicyClosed is returned by Policy.Reload, [Policy.addSource], [Policy.removeSource] and [Policy.replaceSource] if the policy has been closed.
Functions ¶
This section is empty.
Types ¶
type Change ¶
type Change[T any] struct { New, Old T }
Change represents a change from the Old to the New value of type T.
type Policy ¶
type Policy struct {
// contains filtered or unexported fields
}
Policy provides access to the current effective setting.Snapshot for a given scope and allows to reload it from the underlying source.Store list. It also allows to subscribe and receive a callback whenever the effective setting.Snapshot is changed.
It is safe for concurrent use.
func PolicyFor ¶
func PolicyFor(scope setting.PolicyScope) (*Policy, error)
PolicyFor returns the Policy for the specified scope, creating it from the registered [source.Store]s if it doesn't already exist.
func (*Policy) Close ¶
func (p *Policy) Close()
Close initiates the closing of the policy. The Policy.Done channel is closed to signal that the operation has been completed.
func (*Policy) Done ¶
func (p *Policy) Done() <-chan struct{}
Done returns a channel that is closed when the Policy is closed.
func (*Policy) Get ¶
Get returns the effective setting.Snapshot.
func (*Policy) IsValid ¶
IsValid reports whether p is in a valid state and has not been closed.
Since p's state can be changed by other goroutines at any time, this should only be used as an optimization.
func (*Policy) RegisterChangeCallback ¶
func (p *Policy) RegisterChangeCallback(callback PolicyChangeCallback) (unregister func())
RegisterChangeCallback adds a function to be called whenever the effective policy changes. The returned function can be used to unregister the callback.
func (*Policy) Reload ¶
Reload synchronously re-reads policy settings from the underlying list of policy sources, constructing a new merged setting.Snapshot even if the policy remains unchanged. In most scenarios, there's no need to re-read the policy manually. Instead, it is recommended to register a policy change callback, or to use the most recent setting.Snapshot returned by the Policy.Get method.
It must not be called with p.mu held.
func (*Policy) Scope ¶
func (p *Policy) Scope() setting.PolicyScope
Scope returns the setting.PolicyScope that this policy applies to.
type PolicyChange ¶
type PolicyChange struct {
// contains filtered or unexported fields
}
PolicyChange describes a policy change.
func (PolicyChange) HasChanged ¶
func (c PolicyChange) HasChanged(key setting.Key) bool
HasChanged reports whether a policy setting with the specified setting.Key, has changed.
func (PolicyChange) New ¶
func (c PolicyChange) New() *setting.Snapshot
New returns the setting.Snapshot after the change.
func (PolicyChange) Old ¶
func (c PolicyChange) Old() *setting.Snapshot
Old returns the setting.Snapshot before the change.
type PolicyChangeCallback ¶
type PolicyChangeCallback func(*PolicyChange)
PolicyChangeCallback is a function called whenever a policy changes.
type StoreRegistration ¶
type StoreRegistration struct {
// contains filtered or unexported fields
}
StoreRegistration is a source.Store registered for use in the specified scope. It can be used to unregister the store, or replace it with another one.
func RegisterStore ¶
func RegisterStore(name string, scope setting.PolicyScope, store source.Store) (*StoreRegistration, error)
RegisterStore registers a new policy source.Store with the specified name and setting.PolicyScope.
func RegisterStoreForTest ¶
func RegisterStoreForTest(tb internal.TB, name string, scope setting.PolicyScope, store source.Store) (*StoreRegistration, error)
RegisterStoreForTest is like RegisterStore, but unregisters the store when tb and all its subtests complete.
func (*StoreRegistration) ReplaceStore ¶
func (r *StoreRegistration) ReplaceStore(new source.Store) (*StoreRegistration, error)
ReplaceStore replaces the registered store with the new one, returning a new StoreRegistration or an error.
func (*StoreRegistration) Unregister ¶
func (r *StoreRegistration) Unregister() error
Unregister reverts the registration.