Skip to content

Commit 00113f2

Browse files
CI correction with basic changes
1 parent 32999ab commit 00113f2

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

basic

17.9 MB
Binary file not shown.

cmd/examples/basic/main.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package main
22

33
import (
44
"context"
5-
"errors" // Added this import
5+
"errors"
66
"log"
77
"time"
88

@@ -27,18 +27,27 @@ func main() {
2727
dynconf.WithRollback[AppConfig](true),
2828
)
2929

30-
// You might need to use Subscribe() instead of Watch() depending on the package version
31-
changes, err := cfg.Subscribe(ctx) // Changed Watch to Subscribe
32-
if err != nil {
33-
log.Fatal(err) // This directly handles the error from Subscribe
34-
}
30+
// Initialize with a default configuration
31+
initialConfig := AppConfig{
32+
ServerPort: 8080,
33+
Timeout: 5 * time.Second,
34+
}
3535

36+
if err := cfg.Update(ctx, initialConfig); err != nil {
37+
log.Fatal(err)
38+
}
39+
40+
// Subscribe to changes - get both the channel and cleanup function
41+
changes, cleanup := cfg.Subscribe(ctx)
42+
defer cleanup() // Ensure cleanup is called when main exits
43+
44+
// Handle configuration updates in a separate goroutine
3645
go func() {
37-
for newCfg := range changes {
38-
log.Printf("Config updated: %+v", newCfg)
46+
for update := range changes {
47+
log.Printf("Config updated: %+v", update)
3948
}
4049
}()
4150

42-
// Application logic...
51+
// Keep the application running
4352
select {}
4453
}

0 commit comments

Comments
 (0)