Env prefixes doesn't work with array
dongjiang1989 opened this issue · 8 comments
dongjiang1989 commented
ref:
package main
import (
"encoding/json"
"fmt"
"log"
"os"
"github.com/caarlos0/env/v10"
)
type Test struct {
Str string `env:"TEST"`
}
type ComplexConfig struct {
Foos []Test `envPrefix:"FOO_"`
Clean Test `envPrefix:"BAR_"`
}
func main() {
os.Setenv("FOO_TEST", "kek")
os.Setenv("FOO_0_TEST", "kek0")
os.Setenv("FOO_1_TEST", "kek1")
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)
}
output:
{"Foos":null,"Clean":{"Str":"lel"}}
caarlos0 commented
on the top of my head I can't think of a reason why not... if you wanna try pls go for it 🙏
dongjiang1989 commented
@akutuev Will you add pr for this feat? I can help
akutuev commented
@akutuev Will you add pr for this feat? I can help
Hi, no worries, I'm planning to take a look very soon, thanks
Rancbar commented
As I needed this feature too, I created a merge request to handle it. I will be grateful if you review it.
StarpTech commented
The PR has fixed it. When can we expect a release?
caarlos0 commented
just pushed v11.2.0
caarlos0 commented
thanks everyone!