dynconfig

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Snapshot

type Snapshot struct {
	// contains filtered or unexported fields
}

Snapshot captures the current state of all registered dynamic values. Useful for debugging and logging current configuration.

func NewSnapshot

func NewSnapshot() *Snapshot

NewSnapshot creates a new configuration snapshot.

func (*Snapshot) Capture

func (s *Snapshot) Capture() map[string]any

Capture returns the current values of all registered configurations.

func (*Snapshot) Register

func (s *Snapshot) Register(name string, getter func() any)

Register records a named value in the snapshot.

type Value

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

Value holds a configuration value that can be swapped atomically at runtime.

This is the fundamental building block for dynamic configuration. Any policy or config struct can be wrapped in a Value for hot-swapping.

Thread-safe: reads use atomic.Value, writes use sync.Mutex.

func NewValue

func NewValue[T any](initial T) *Value[T]

NewValue creates a new dynamic value with an initial setting.

func (*Value[T]) Get

func (v *Value[T]) Get() T

Get returns the current value. Lock-free read.

func (*Value[T]) OnChange

func (v *Value[T]) OnChange(fn func(old, new T))

OnChange registers a callback that fires when the value changes. The callback receives the old and new values. Callbacks are best-effort and must not block.

func (*Value[T]) Set

func (v *Value[T]) Set(newVal T)

Set atomically replaces the value and notifies listeners.

Jump to

Keyboard shortcuts

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