ilyakaznacheev / cleanenv

✨Clean and minimalistic environment configuration reader for Golang
MIT License
1.67k stars 116 forks source link

Config returns nothing #128

Closed StephanMa closed 1 year ago

StephanMa commented 1 year ago

Dear all, I try to read a config yaml into a struct... I verified that the path is correct and the struct matches the file content. After the reading step, I don't receive any error.... unfortunately the variable is complete empty...

e.g.

type ConfigYAML struct {
    Configuration struct {
        id           string   `yaml:"id" env:"ID" env-description:"Config ID"`
        name         string   `yaml:"name" env:"NAME" env-description:"Config Name"`
        description  string   `yaml:"description" env:"DESC" env-description:"Config ID"`
        asynchronous bool     `yaml:"async" env:"ASYNC" env-description:"Config Async flag"`
        active       bool     `yaml:"active" env:"ACTIVE" env-description:"Config Active flag"`
        commands     []string `yaml:"commands" env:"COMMANDS" env-description:"Config Commands"`
    } `yaml:"configuration"`
}

...
var newconfyaml ConfigYAML

newpath := filepath.Join(strPath, f.Name())
if err = cleanenv.ReadConfig(newpath, &newconfyaml); err != nil {
  fmt.Println(err)
  os.Exit(2)
}

The path points to the existing yaml

Here the content

configuration:
  id: 7fe76a79-4a98-4d60-b13f-d4bf4235860f
  name: localhost
  description: Localhost
  async: False
  active: True
  commands:
    - curl localhost

Do you have any clue what's going on?

go 1.18

require (
    github.com/google/uuid v1.1.2
    github.com/ilyakaznacheev/cleanenv v1.5.0
    github.com/wailsapp/wails/v2 v2.5.1
    go.etcd.io/bbolt v1.3.7
    golang.org/x/net v0.7.0
)

require (
    github.com/BurntSushi/toml v1.2.1 // indirect
    github.com/bep/debounce v1.2.1 // indirect
    github.com/go-ole/go-ole v1.2.6 // indirect
    github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e // indirect
    github.com/joho/godotenv v1.5.1 // indirect
    github.com/labstack/echo/v4 v4.9.0 // indirect
    github.com/labstack/gommon v0.3.1 // indirect
    github.com/leaanthony/go-ansi-parser v1.0.1 // indirect
    github.com/leaanthony/gosod v1.0.3 // indirect
    github.com/leaanthony/slicer v1.5.0 // indirect
    github.com/mattn/go-colorable v0.1.11 // indirect
    github.com/mattn/go-isatty v0.0.14 // indirect
    github.com/pkg/browser v0.0.0-20210706143420-7d21f8c997e2 // indirect
    github.com/pkg/errors v0.9.1 // indirect
    github.com/samber/lo v1.27.1 // indirect
    github.com/tkrajina/go-reflector v0.5.5 // indirect
    github.com/valyala/bytebufferpool v1.0.0 // indirect
    github.com/valyala/fasttemplate v1.2.1 // indirect
    github.com/wailsapp/mimetype v1.4.1 // indirect
    golang.org/x/crypto v0.1.0 // indirect
    golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect
    golang.org/x/sys v0.5.0 // indirect
    golang.org/x/text v0.7.0 // indirect
    gopkg.in/yaml.v3 v3.0.1 // indirect
    olympos.io/encoding/edn v0.0.0-20201019073823-d3554ca0b0a3 // indirect
)