Skip to content

Commit

Permalink
docs: more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Aug 7, 2024
1 parent 19de57d commit be1c262
Show file tree
Hide file tree
Showing 3 changed files with 360 additions and 169 deletions.
143 changes: 0 additions & 143 deletions env_examples_test.go

This file was deleted.

26 changes: 0 additions & 26 deletions env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1403,32 +1403,6 @@ func TestPrecedenceUnmarshalText(t *testing.T) {
isEqual(t, []LogLevel{DebugLevel, InfoLevel}, cfg.LogLevels)
}

func ExampleParseWithOptions() {
type thing struct {
desc string
}

type conf struct {
Thing thing `env:"THING"`
}

os.Setenv("THING", "my thing")

c := conf{}

err := ParseWithOptions(&c, Options{FuncMap: map[reflect.Type]ParserFunc{
reflect.TypeOf(thing{}): func(v string) (interface{}, error) {
return thing{desc: v}, nil
},
}})
if err != nil {
fmt.Println(err)
}
fmt.Println(c.Thing.desc)
// Output:
// my thing
}

func TestFile(t *testing.T) {
type config struct {
SecretKey string `env:"SECRET_KEY,file"`
Expand Down
Loading

0 comments on commit be1c262

Please sign in to comment.