8000 Env prefixes doesn't work with array · Issue #298 · caarlos0/env · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Env prefixes doesn't work with array #298
Closed
@dongjiang1989

Description

@dongjiang1989

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"}}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0