-
-
Notifications
You must be signed in to change notification settings - Fork 275
Env prefixes doesn't work with pointers #202
Copy link
Copy link
Closed
Labels
Description
Example
package main
import (
"encoding/json"
"fmt"
"log"
"os"
"github.com/caarlos0/env/v6"
)
type Test struct {
Str string `env:"TEST"`
}
type ComplexConfig struct {
Foo *Test `envPrefix:"FOO_"`
Bar *Test `envPrefix:"BAR_"`
Clean *Test
}
func main() {
os.Setenv("FOO_TEST", "kek")
os.Setenv("BAR_TEST", "lel")
cfg := ComplexConfig{
Foo: &Test{},
Bar: &Test{},
Clean: &Test{},
}
err := env.Parse(&cfg)
if err != nil {
log.Fatal(err)
}
confBytes, _ := json.Marshal(cfg)
fmt.Printf("%s", confBytes)
}output :
{"Foo":{"Str":""},"Bar":{"Str":""},"Clean":{"Str":""}}
Reactions are currently unavailable