Skip to content

Commit

Permalink
Make examples match reality
Browse files Browse the repository at this point in the history
  • Loading branch information
NHAS committed Nov 9, 2024
1 parent 6d5e42b commit 8e6875a
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,17 @@ func main() {
fmt.Printf("Loaded YAML config: %+v\n", yamlLoadedConfig)

// They're the same!

}
```

Output
```sh
Loaded config: {Database:{Host:localhost Port:5432 User:dbuser Password:securepassword} Renamed:some_value}
Loaded config: {Database:{Host:localhost Port:5432 User:dbuser Password:securepassword} Renamed:some_value}
```


### Environment Variables
For struct:
```go
Expand All @@ -106,19 +113,21 @@ type Config struct {
}

func main() {
populatedConfig, warnings, err := confy.Config[Config](confy.FromCli(confy.DefaultCliDelimiter))
populatedConfig, _, err := confy.Config[Config](confy.FromEnvs(confy.DefaultENVDelimiter))
if err != nil {
fmt.Println("Error loading config:", err)
return
}

fmt.Println(populatedConfig.Database.Port)
fmt.Println(populatedConfig.Server.Host)
}
```
Expected environment variable:

```sh
export Server_Host="localhost"
$ ./test
localhost
```

### CLI Flags only
Expand All @@ -138,7 +147,7 @@ type Config struct {
}

func main() {
populatedConfig, warnings, err := confy.Config[Config](confy.FromCli(confy.DefaultCliDelimiter))
populatedConfig, _, err := confy.Config[Config](confy.FromCli(confy.DefaultCliDelimiter))
if err != nil {
fmt.Println("Error loading config:", err)
return
Expand All @@ -150,7 +159,7 @@ func main() {
```
Expected CLI flag:
```sh
./app -Database.Port=5432
$ ./app -Database.Port=5432
5432
```

Expand Down

0 comments on commit 8e6875a

Please sign in to comment.