Documentation
¶
Overview ¶
Package gs_dync provides dynamic configuration binding and refresh capabilities for Go-Spring applications.
It enables hot-reload of configuration in long-running applications through a two-phase commit mechanism that ensures system consistency. Components register themselves during IOC container initialization and can be batch-refreshed at runtime.
Two-phase refresh:
- Pre-refresh (commit=false): Validates all objects against new configuration. On failure, the old configuration is preserved and no changes are applied.
- Commit (commit=true): Atomically applies validated configuration to all objects.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Errors ¶
type Errors struct {
// contains filtered or unexported fields
}
Errors represents a collection of errors.
type Properties ¶
type Properties struct {
// contains filtered or unexported fields
}
Properties manages dynamic properties and refreshable objects. It serves two distinct phases:
1. Initialization Phase (IOC Container Startup):
- RefreshField is called for each configuration-bound field
- Registers refreshable objects in the internal objects slice
- Sets initial configuration values immediately (commit=true)
2. Runtime Phase (Dynamic Configuration Updates):
- Refresh is called with new configuration data
- Executes two-phase refresh: validate all objects first, then commit
- On validation failure, automatically restores the previous configuration
- Thread-safe: All operations are protected by RWMutex
func New ¶
func New(p flatten.Storage) *Properties
New creates and returns a new Properties instance.
func (*Properties) Data ¶
func (p *Properties) Data() flatten.Storage
Data returns the current properties.
func (*Properties) ObjectsCount ¶
func (p *Properties) ObjectsCount() int
ObjectsCount returns the number of registered refreshable objects.
func (*Properties) Refresh ¶
func (p *Properties) Refresh(prop flatten.Storage) (err error)
Refresh updates the properties and refreshes all bound objects using a two-phase commit.
This method is designed for runtime dynamic configuration updates. It ensures that either all objects are successfully refreshed with the new configuration, or none are, maintaining system consistency. It is thread-safe.
func (*Properties) RefreshField ¶
RefreshField refreshes a field of a bean and optionally registers it as refreshable.
This method is exclusively used during the IOC container initialization phase to:
- Bind configuration values to struct fields
- Register fields that implement refreshable for future batch refreshes
Parameters:
- v: Reflect value of the field (must be a pointer to the actual field)
- param: Binding parameters including configuration key and path
Note: For runtime configuration updates, use Refresh method instead.
type Value ¶
type Value[T any] struct { // contains filtered or unexported fields }
Value represents a thread-safe container that stores a dynamic configuration value. Its value can be updated atomically via onRefresh.
Key features:
- Type-safe: Generic type parameter ensures compile-time type safety.
- Atomic access: Uses atomic.Value for lock-free concurrent reads and writes.
- JSON serializable: Implements json.Marshaler for easy debugging and monitoring.
- Zero-value safe: Returns zero value when no configuration has been set yet.
Typical usage:
type Config struct {
Timeout gs_dync.Value[time.Duration] `value:"${server.timeout:=30s}"`
}
During IOC initialization, the field is bound to configuration. At runtime, calling Properties.Refresh() updates all registered Value fields atomically.
func (*Value[T]) MarshalJSON ¶
MarshalJSON serializes the stored value as JSON.