Skip to content

Commit

Permalink
docs: DefaultValueTagName example
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed Aug 24, 2024
1 parent 17fdb91 commit 84c7739
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,20 +354,22 @@ func ExampleParseWithOptions_prefix() {
// Output: {Foo:a}
}

// Use a different tag name than `env`.
// Use a different tag name than `env` and `envDefault`.
func ExampleParseWithOptions_tagName() {
type Config struct {
Home string `json:"HOME"`
Page string `json:"PAGE" def:"world"`
}
os.Setenv("HOME", "hello")
var cfg Config
if err := ParseWithOptions(&cfg, Options{
TagName: "json",
TagName: "json",
DefaultValueTagName: "def",
}); err != nil {
fmt.Println(err)
}
fmt.Printf("%+v", cfg)
// Output: {Home:hello}
// Output: {Home:hello Page:world}
}

// If you don't want to set the `env` tag on every field, you can use the
Expand Down

0 comments on commit 84c7739

Please sign in to comment.