Skip to content

Commit

Permalink
docs: fix bad example
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Alexandro Becker <[email protected]>
  • Loading branch information
caarlos0 committed Aug 7, 2024
1 parent fb84246 commit 5d7eb0c
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ func ExampleParseWithOptions_customTypes() {
// Make all fields required by default.
func ExampleParseWithOptions_allFieldsRequired() {
type Config struct {
Username string `env:"USERNAME" envDefault:"admin"`
Password string `env:"PASSWORD"`
Username string `env:"EX_USERNAME" envDefault:"admin"`
Password string `env:"EX_PASSWORD"`
}

var cfg Config
Expand All @@ -252,23 +252,23 @@ func ExampleParseWithOptions_allFieldsRequired() {
fmt.Println(err)
}
fmt.Printf("%+v\n", cfg)
// Output: env: required environment variable "PASSWORD" is not set
// Output: env: required environment variable "EX_PASSWORD" is not set
// {Username:admin Password:}
}

// Set a custom environment.
// By default, `os.Environ()` is used.
func ExampleParseWithOptions_setEnv() {
type Config struct {
Username string `env:"USERNAME" envDefault:"admin"`
Password string `env:"PASSWORD"`
Username string `env:"EX_USERNAME" envDefault:"admin"`
Password string `env:"EX_PASSWORD"`
}

var cfg Config
if err := ParseWithOptions(&cfg, Options{
Environment: map[string]string{
"USERNAME": "john",
"PASSWORD": "cena",
"EX_USERNAME": "john",
"EX_PASSWORD": "cena",
},
}); err != nil {
fmt.Println(err)
Expand Down

0 comments on commit 5d7eb0c

Please sign in to comment.