From 184d67269aa713e7eaa152e18cec1978d5b07461 Mon Sep 17 00:00:00 2001 From: Nick Tan Date: Fri, 15 Sep 2023 00:11:50 -0700 Subject: [PATCH] breaking change: #233 update example with new provider signature --- examples/complex-etcd/main.go | 25 ++++++++++++++++++++----- examples/read-appconfig/main.go | 6 +++++- examples/read-consul/main.go | 30 ++++++++++++++++++++++++------ examples/read-vault/main.go | 5 ++++- 4 files changed, 53 insertions(+), 13 deletions(-) diff --git a/examples/complex-etcd/main.go b/examples/complex-etcd/main.go index 795dfc6c..95f0e370 100644 --- a/examples/complex-etcd/main.go +++ b/examples/complex-etcd/main.go @@ -70,7 +70,10 @@ func main() { Prefix: false, Key: "single_key", } - provider := etcd.Provider(providerCfg) + provider, err := etcd.Provider(providerCfg) + if err != nil { + log.Fatal("Failed to instantiate etcd provider: %v", err) + } if err := kCheck.Load(provider, nil); err != nil { log.Fatalf("error loading config: %v", err) @@ -109,7 +112,10 @@ func main() { Prefix: true, Key: "parent", } - provider = etcd.Provider(providerCfg) + provider, err = etcd.Provider(providerCfg) + if err != nil { + log.Fatal("Failed to instantiate etcd provider: %v", err) + } if err := kCheck.Load(provider, nil); err != nil { log.Fatalf("error loading config: %v", err) @@ -154,7 +160,10 @@ func main() { Key: "child", } - provider = etcd.Provider(providerCfg) + provider, err = etcd.Provider(providerCfg) + if err != nil { + log.Fatal("Failed to instantiate etcd provider: %v", err) + } if err := kCheck.Load(provider, nil); err != nil { log.Fatalf("error loading config: %v", err) @@ -201,7 +210,10 @@ func main() { Key: "child", } - provider = etcd.Provider(providerCfg) + provider, err = etcd.Provider(providerCfg) + if err != nil { + log.Fatal("Failed to instantiate etcd provider: %v", err) + } if err := kCheck.Load(provider, nil); err != nil { log.Fatalf("error loading config: %v", err) @@ -241,7 +253,10 @@ func main() { Key: "child", } - provider = etcd.Provider(providerCfg) + provider, err = etcd.Provider(providerCfg) + if err != nil { + log.Fatal("Failed to instantiate etcd provider: %v", err) + } if err := kCheck.Load(provider, nil); err != nil { log.Fatalf("error loading config: %v", err) diff --git a/examples/read-appconfig/main.go b/examples/read-appconfig/main.go index 4808e993..cafd3956 100644 --- a/examples/read-appconfig/main.go +++ b/examples/read-appconfig/main.go @@ -13,12 +13,16 @@ import ( var k = koanf.New(".") func main() { - provider := appconfig.Provider(appconfig.Config{ + provider, err := appconfig.Provider(appconfig.Config{ Application: os.Getenv("AWS_APPCONFIG_APPLICATION"), ClientID: os.Getenv("AWS_APPCONFIG_CLIENT_ID"), Configuration: os.Getenv("AWS_APPCONFIG_CONFIG_NAME"), Environment: os.Getenv("AWS_APPCONFIG_ENVIRONMENT"), }) + if err != nil { + log.Fatal("Failed to instantiate appconfig provider: %v", err) + } + // Load the provider and parse configuration as JSON. if err := k.Load(provider, json.Parser()); err != nil { log.Fatalf("error loading config: %v", err) diff --git a/examples/read-consul/main.go b/examples/read-consul/main.go index d0acaa1a..23bdb0b9 100644 --- a/examples/read-consul/main.go +++ b/examples/read-consul/main.go @@ -54,12 +54,15 @@ func main() { log.Printf("Couldn't put key.") } - provider := consul.Provider(consul.Config{ + provider, err := consul.Provider(consul.Config{ Key: sKey, Recurse: false, Detailed: false, Cfg: api.DefaultConfig(), }) + if err != nil { + log.Fatal("Failed to instantiate consul provider: %v", err) + } if err := kCheck.Load(provider, nil); err != nil { log.Fatalf("error loading config: %v", err) @@ -91,12 +94,15 @@ func main() { log.Fatalf("error loading config: %v", err) } - provider = consul.Provider(consul.Config{ + provider, err = consul.Provider(consul.Config{ Key: "parent", Recurse: true, Detailed: false, Cfg: api.DefaultConfig(), }) + if err != nil { + log.Fatal("Failed to instantiate consul provider: %v", err) + } if err := kCheck.Load(provider, nil); err != nil { log.Fatalf("error loading config: %v", err) @@ -134,12 +140,15 @@ func main() { log.Fatalf("error loading config: %v", err) } - provider = consul.Provider(consul.Config{ + provider, err = consul.Provider(consul.Config{ Key: "child", Recurse: true, Detailed: false, Cfg: api.DefaultConfig(), }) + if err != nil { + log.Fatal("Failed to instantiate consul provider: %v", err) + } if err := kCheck.Load(provider, nil); err != nil { log.Fatalf("error loading config: %v", err) @@ -181,12 +190,15 @@ func main() { sFlags := uint64(42) sVal = "father" - provider = consul.Provider(consul.Config{ + provider, err = consul.Provider(consul.Config{ Key: sKey, Recurse: false, Detailed: true, Cfg: api.DefaultConfig(), }) + if err != nil { + log.Fatal("Failed to instantiate consul provider: %v", err) + } if err := kCheck.Load(provider, nil); err != nil { fmt.Printf("error loading config: %v", err) @@ -213,12 +225,15 @@ func main() { sKey = "parent" - provider = consul.Provider(consul.Config{ + provider, err = consul.Provider(consul.Config{ Key: sKey, Recurse: true, Detailed: true, Cfg: api.DefaultConfig(), }) + if err != nil { + log.Fatal("Failed to instantiate consul provider: %v", err) + } if err := kCheck.Load(provider, nil); err != nil { fmt.Printf("error loading config: %v", err) @@ -255,12 +270,15 @@ func main() { // Watch test sKey = "parent" - provider = consul.Provider(consul.Config{ + provider, err = consul.Provider(consul.Config{ Key: sKey, Recurse: true, Detailed: false, Cfg: api.DefaultConfig(), }) + if err != nil { + log.Fatal("Failed to instantiate consul provider: %v", err) + } // Getting the old value kCheck.Load(provider, nil) diff --git a/examples/read-vault/main.go b/examples/read-vault/main.go index c03442af..05bd621c 100644 --- a/examples/read-vault/main.go +++ b/examples/read-vault/main.go @@ -14,7 +14,7 @@ import ( var k = koanf.New(".") func main() { - provider := vault.Provider(vault.Config{ + provider, err := vault.Provider(vault.Config{ Address: os.Getenv("VAULT_ADDRESS"), Token: os.Getenv("VAULT_TOKEN"), Path: "secret/data/my-app", @@ -25,6 +25,9 @@ func main() { // k.String("data.YOUR_KEY") etc. instead of k.String("YOUR_KEY"). ExcludeMeta: true, }) + if err != nil { + log.Fatal("Cannot load vault provider: %v", err) + } // Load mapped config from Vault storage. if err := k.Load(provider, nil); err != nil { log.Fatalf("error loading config: %v", err)