Skip to content

Commit

Permalink
docs(examples): apply latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nikoksr committed Aug 9, 2024
1 parent 8709ea5 commit 197ddce
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
7 changes: 3 additions & 4 deletions examples/complex/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"fmt"
"log"
"time"

"github.com/nikoksr/konfetty"
Expand Down Expand Up @@ -92,7 +92,7 @@ func main() {
}

// Use konfetty to process the config
cfg, err := konfetty.FromConfig(cfg).
cfg, err := konfetty.FromStruct(cfg).
WithDefaults(
// Default for all BaseDevice instances
BaseDevice{
Expand Down Expand Up @@ -141,8 +141,7 @@ func main() {
}).
Build()
if err != nil {
fmt.Printf("Error processing config: %v\n", err)
return
log.Fatalf("Error building config: %v", err)
}

// The processed config would look like this:
Expand Down
6 changes: 3 additions & 3 deletions examples/koanf/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"fmt"
"errors"
"log"

"github.com/knadh/koanf/parsers/yaml"
Expand Down Expand Up @@ -51,7 +51,7 @@ func main() {
// Simply pass the config to konfetty and let it handle the rest.
//

cfg, err = konfetty.FromConfig(cfg).
cfg, err = konfetty.FromStruct(cfg).
WithDefaults(
AppConfig{
Database: DatabaseConfig{
Expand All @@ -71,7 +71,7 @@ func main() {
}).
WithValidator(func(c *AppConfig) error {
if c.Database.Username == "" || c.Database.Password == "" {
return fmt.Errorf("database credentials are required")
return errors.New("database credentials are required")
}
return nil
}).
Expand Down
12 changes: 6 additions & 6 deletions examples/simple/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"fmt"
"errors"
"log"

"github.com/nikoksr/konfetty"
Expand Down Expand Up @@ -31,10 +31,12 @@ func main() {
Crust: "thin",
},
Quantity: 1,
Delivery: true,
Address: "A-123, 4th Street, New York",
}

// Use konfetty to process the config
cfg, err := konfetty.FromConfig(cfg).
cfg, err := konfetty.FromStruct(cfg).
WithDefaults(
OrderConfig{
Pizza: PizzaConfig{
Expand All @@ -54,7 +56,7 @@ func main() {
}).
WithValidator(func(c *OrderConfig) error {
if c.Delivery && c.Address == "" {
return fmt.Errorf("delivery address is required for delivery orders")
return errors.New("delivery address is required for delivery orders")
}
return nil
}).
Expand All @@ -80,8 +82,6 @@ func main() {
// },
// Quantity: 1,
// Delivery: true,
// Address: "",
// Address: "A-123, 4th Street, New York",
// }
//
// Note: The above configuration would fail validation due to missing address for delivery.
}
6 changes: 3 additions & 3 deletions examples/viper/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"fmt"
"errors"
"log"

"github.com/spf13/viper"
Expand Down Expand Up @@ -47,7 +47,7 @@ func main() {
}

// Use konfetty to handle the rest
cfg, err = konfetty.FromConfig(cfg).
cfg, err = konfetty.FromStruct(cfg).
WithDefaults(
AppConfig{
Database: DatabaseConfig{
Expand All @@ -67,7 +67,7 @@ func main() {
}).
WithValidator(func(c *AppConfig) error {
if c.Database.Username == "" || c.Database.Password == "" {
return fmt.Errorf("database credentials are required")
return errors.New("database credentials are required")
}
return nil
}).
Expand Down

0 comments on commit 197ddce

Please sign in to comment.