Documentation ¶
Overview ¶
Package streamingconfig provides functionality for using dynamic configuration functionalities.
Index ¶
- Variables
- func WithCollectionName[T Config](collectionName string) func(repo *WatchedRepo[T])
- func WithNowFn[T Config](nf func() time.Time) func(*WatchedRepo[T])
- func WithSkipIndexOperations[T Config]() func(*WatchedRepo[T])
- type Args
- type Config
- type ListConfigDatesQuery
- type ListVersionedConfigsQuery
- type UpdateConfigCmd
- type Versioned
- type WatchedRepo
- func (s *WatchedRepo[T]) GetConfig() (T, error)
- func (s *WatchedRepo[T]) GetLatestVersion() (*Versioned[T], error)
- func (s *WatchedRepo[T]) ListVersionedConfigs(ctx context.Context, query ListVersionedConfigsQuery) ([]*Versioned[T], error)
- func (s *WatchedRepo[T]) ListVersionedConfigsByDate(ctx context.Context, query ListConfigDatesQuery) ([]*Versioned[T], error)
- func (s *WatchedRepo[T]) Start(ctx context.Context) (<-chan struct{}, error)
- func (s *WatchedRepo[T]) UpdateConfig(ctx context.Context, cmd UpdateConfigCmd[T]) (*Versioned[T], error)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotStarted is returned when a user attempts to use the store before calling the `Start` method. ErrNotStarted = errors.New("config store not started - call Start() before using it") ErrConfigurationNotFound = errors.New("configuration not found") // ErrConcurrentUpdate signals that multiple repositories are attempting to change the configuration concurrently. ErrConcurrentUpdate = errors.New("configuration concurrently being updated by someone-else") // ErrTypeMustBePointer by the constructor of the repo if the provided type is not a pointer type. ErrTypeMustBePointer = errors.New("configuration type argument must be pointer") )
Functions ¶
func WithCollectionName ¶
func WithCollectionName[T Config](collectionName string) func(repo *WatchedRepo[T])
func WithSkipIndexOperations ¶
func WithSkipIndexOperations[T Config]() func(*WatchedRepo[T])
Types ¶
type Config ¶
Config is a representation of the app configuration. It is wrapped into a generic configuration which includes additional fields for the sake of auditability (version, updated_at and updated_by).
type ListConfigDatesQuery ¶
type ListConfigDatesQuery struct { // From is the time from which retrieve the configs (inclusive) From time.Time // To is the time until which retrieve the configs (exclusive) To time.Time }
ListConfigDatesQuery provide query parameters for listing configurations by dates.
type ListVersionedConfigsQuery ¶
type ListVersionedConfigsQuery struct { // FromVersion version from which retrieve the configs (inclusive) FromVersion uint32 // ToVersion version until which retrieve the configs (exclusive) ToVersion uint32 }
ListVersionedConfigsQuery provide query parameters for listing configurations by version.
type UpdateConfigCmd ¶
type Versioned ¶
type Versioned[T Config] struct { // Version is used as unique ID of the config collection. Version uint64 `json:"version" bson:"_id"` // UpdatedBy author of the config update UpdatedBy string `json:"updated_by" bson:"updated_by"` // CreatedAt time of the last config update. CreatedAt time.Time `json:"created_at" bson:"created_at"` // Config embeds the application-specific configuration. Config T `json:"config" bson:"app_config"` }
Versioned encapsulates a version of the configuration and adds some auditing information on top of the configuration.
type WatchedRepo ¶
type WatchedRepo[T Config] struct { // contains filtered or unexported fields }
func NewWatchedRepo ¶
func NewWatchedRepo[T Config]( args Args, opts ...func(*WatchedRepo[T]), ) (*WatchedRepo[T], error)
func (*WatchedRepo[T]) GetConfig ¶
func (s *WatchedRepo[T]) GetConfig() (T, error)
GetConfig gets the current user-defined configuration with defaults applied to it.
func (*WatchedRepo[T]) GetLatestVersion ¶
func (s *WatchedRepo[T]) GetLatestVersion() (*Versioned[T], error)
GetLatestVersion returns the latest version of the user-provided configuration along with auditing data.
func (*WatchedRepo[T]) ListVersionedConfigs ¶
func (s *WatchedRepo[T]) ListVersionedConfigs( ctx context.Context, query ListVersionedConfigsQuery, ) ([]*Versioned[T], error)
ListVersionedConfigs returns a list of the user-provided configuration versions along with auditing data.
func (*WatchedRepo[T]) ListVersionedConfigsByDate ¶
func (s *WatchedRepo[T]) ListVersionedConfigsByDate( ctx context.Context, query ListConfigDatesQuery, ) ([]*Versioned[T], error)
ListVersionedConfigsByDate returns a list of the user-provided configuration versions along with auditing data.
func (*WatchedRepo[T]) Start ¶
func (s *WatchedRepo[T]) Start(ctx context.Context) (<-chan struct{}, error)
Start is a non-blocking call that starts the store and watches for updates on the persisted configurations.
For graceful shutdown, cancel the input context and wait for the returned channel to be closed.
func (*WatchedRepo[T]) UpdateConfig ¶
func (s *WatchedRepo[T]) UpdateConfig(ctx context.Context, cmd UpdateConfigCmd[T]) (*Versioned[T], error)
UpdateConfig retrieves the latest configuration, modifies it by calling the underlying `Update` method and creates a new updated version.