configsrc

package
v0.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package configsrc resolves a store's configuration: from a copy of the one given to the store's WithConfig option, or else by binding the store's defaults from a gas.ConfigProvider.

Usage

A store keeps a Source of its Config, which WithConfig sets, and resolves a fresh configuration on each Init:

var src configsrc.Source[Config]
src.Set(cfg) // from WithConfig, or never
resolved, err := src.Resolve(cfgProvider, DefaultConfig, rules)

Resolving

Source.Resolve never returns, and never changes, the struct given to Set: it returns a copy. With a configuration given to Set, the copy is checked against its `validate` tags; a nil one is an error wrapping queue.ErrNilConfig. Without one, the defaults are bound from the Binder, which checks the tags itself; a nil Binder is an error wrapping queue.ErrNoConfigProvider. Then the store's rules run on the result.

Errors

A failed tag check, bind or rule wraps queue.ErrInvalidConfig, and, for the first two, the validator's or the binder's error, so that errors.As reaches validator.ValidationErrors. The errors, before the store's prefix:

config is nil
no config provider
invalid config: validate config: <the validator's error>
invalid config: <the binder's error>
invalid config: <the rule's error>

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Binder

type Binder interface {
	// Bind fills the struct dest points to, then validates it.
	Bind(dest any) error
}

Binder fills a struct from configuration and validates it. gas.ConfigProvider implements it.

type Source

type Source[T any] struct {
	// contains filtered or unexported fields
}

Source records where a store takes its configuration from, as described in the package documentation. The zero Source binds from the Binder.

func (*Source[T]) Resolve

func (s *Source[T]) Resolve(b Binder, defaults func() *T, check func(*T) error) (*T, error)

Resolve returns a new configuration: a copy of the one given to Set, checked against its validate tags, or else the result of defaults bound from b. It then runs check on it and returns it only if every check passes.

func (*Source[T]) Set

func (s *Source[T]) Set(cfg *T)

Set records cfg as the configuration given to WithConfig. It only records it: a nil cfg is recorded too, and makes Resolve fail with queue.ErrNilConfig.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL