Skip to content

Commit

Permalink
breaking change: #233 update example with new provider signature
Browse files Browse the repository at this point in the history
  • Loading branch information
missedone committed Sep 15, 2023
1 parent eb3c196 commit 184d672
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 13 deletions.
25 changes: 20 additions & 5 deletions examples/complex-etcd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion examples/read-appconfig/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 24 additions & 6 deletions examples/read-consul/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion examples/read-vault/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)
Expand Down

0 comments on commit 184d672

Please sign in to comment.