-
-
Notifications
You must be signed in to change notification settings - Fork 275
Pointer structs not created with env prefixes #234
Copy link
Copy link
Closed
Description
Following the issue raised in #202, if a pointer struct is used then the default object is not created - this is different to a non-pointer object. See the following 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{}
err := env.Parse(&cfg)
if err != nil {
log.Fatal(err)
}
confBytes, _ := json.Marshal(cfg)
fmt.Printf("%s", confBytes)
}This results in:
{"Foo":null,"Bar":{"Str":"lel"},"Clean":null}Notice how Foo is null, but Bar has the object created.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels