15
15
*/
16
16
17
17
/*
18
- Package gs_dync provides dynamic configuration binding and
19
- refresh capabilities for Go applications.
18
+ Package gs_dync provides dynamic configuration binding and refresh capabilities for Go applications.
20
19
21
- Features:
22
- - Thread-safe atomic.Value based storage with automatic type conversion
23
- - Property change listeners with channel-based notifications
24
- - Hierarchical configuration key resolution (supports nested structs and map keys)
25
- - Live configuration updates with granular change detection
26
- - JSON serialization support for configuration values
20
+ This package is built on thread-safe atomic.Value storage with automatic type conversion and supports change listeners,
21
+ making it suitable for components or services that need to react to configuration updates at runtime.
22
+
23
+ Key Features:
24
+ - Type-safe and thread-safe encapsulation of configuration values
25
+ - Change notification mechanism using channels
26
+ - Hierarchical key resolution for nested structs and map keys
27
+ - Fine-grained refresh logic that only updates affected objects
28
+ - JSON serialization support for value persistence and transmission
27
29
28
30
Examples:
29
31
@@ -33,7 +35,7 @@ Basic value binding:
33
35
_ = v.onRefresh(conf.Map(map[string]any{"key": 42}), conf.BindParam{Key: "key"})
34
36
fmt.Print(v.Value()) // Output: 42
35
37
36
- Struct binding with nested configuration :
38
+ Binding nested structs :
37
39
38
40
type Config struct {
39
41
Server struct {
@@ -44,11 +46,6 @@ Struct binding with nested configuration:
44
46
var cfg Config
45
47
_ = p.RefreshField(reflect.ValueOf(&cfg), conf.BindParam{Key: "config"})
46
48
47
- JSON serialization:
48
-
49
- b, _ := json.Marshal(map[string]any{"key": &v})
50
- fmt.Print(string(b)) // Output: {"key":42}
51
-
52
49
Change notification:
53
50
54
51
listener := v.NewListener()
@@ -57,6 +54,9 @@ Change notification:
57
54
fmt.Print("value changed!")
58
55
}()
59
56
_ = v.onRefresh(conf.Map(map[string]any{"key": 100}), conf.BindParam{Key: "key"})
57
+
58
+ This package is ideal for use cases that require hot-reloading of configuration, have complex config structures,
59
+ or demand reactive behavior to configuration changes.
60
60
*/
61
61
package gs_dync
62
62
0 commit comments