### SNS Notifier for AppConfig and S3 Source: https://github.com/nil-go/konf/blob/main/README.md Register S3 and AppConfig loaders with an SNS notifier to receive change notifications. Start the notifier in a separate goroutine. ```go notifier := sns.NewNotifier("konf-test") notifier.Register(s3Loader, appConfigLoader) go func() { if err := notifier.Start(ctx); err != nil { // handle error } }() ``` -------------------------------- ### Read Server Configuration and Register Change Callbacks Source: https://github.com/nil-go/konf/blob/main/README.md Shows how to read server configuration with default values and register callbacks to be executed when the configuration changes. Assumes configuration has been loaded previously. ```go func (app *appObject) Run() { // Server configuration with default values. serverConfig := struct { Host string Port int }{ Host: "localhost", Port: "8080", } // Read the server configuration. if err := konf.Unmarshal("server", &serverConfig); err != nil { // Handle error here. } // Register callbacks while server configuration changes. konf.OnChange(func() { // Reconfig the application object. }, "server") // ... use cfg in app code ... } ``` -------------------------------- ### Load Configuration from Embed FS and Environment Variables Source: https://github.com/nil-go/konf/blob/main/README.md Demonstrates loading configuration from an embedded file system and environment variables early in the application's lifecycle. Handles potential errors during loading. ```go //go:embed config var config embed.FS func main() { var config konf.Config // Load configuration from embed file system. if err := config.Load(fs.New(config, "config/config.json")); err != nil { // Handle error here. } // Load configuration from environment variables. if err := config.Load(env.New(env.WithPrefix("server"))); err != nil { // Handle error here. } // Watch the changes of configuration. go func() { if err := config.Watch(ctx); err != nil { // Handle error here. } }() konf.SetDefault(config) // ... other setup code ... } ``` -------------------------------- ### Explain Configuration Value Origin Source: https://github.com/nil-go/konf/blob/main/README.md Use Config.Explain to understand how a specific configuration value was resolved from different loaders. Sensitive information is automatically blurred. ```go config.nest has value [map] is loaded by map. Here are other value(loader)s: - env(env) ``` -------------------------------- ### Load Configuration with Cobra Flags Source: https://github.com/nil-go/konf/blob/main/README.md Integrate Konf with Cobra CLI applications by using the pflag loader and the WithFlagSet option to bind Cobra's flags. ```go config.Load(kflag.New(&config, kflag.WithFlagSet(yourCobraCmd.Flags()))) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.