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 b40e58a commit ae81ce5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
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("Cannot 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("Cannot 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("Cannot 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("Cannot 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("Cannot 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("Cannot 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("Cannot 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 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 ae81ce5

Please sign in to comment.