gookit / config

📝 Go configuration manage(load,get,set,export). support JSON, YAML, TOML, Properties, INI, HCL, ENV and Flags. Multi file load, data override merge, parse ENV var. Go应用配置加载管理,支持多种格式,多文件加载,远程文件加载,支持数据合并,解析环境变量名

Home Page:https://pkg.go.dev/github.com/gookit/config/v2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fail fast for required values

x80486 opened this issue · comments

commented

I'm integrating gookit/config in an existing project in order to manage the configuration. I've ran into some issues, but I've been able to workaround them in one way or another — I'm pretty new to Go as well 😬

What I've been able to do is to be able to interrupt the application bootstrapping when there is a missing value. For instance, consider the following configuration:

---
datasource:
  password: ${DATABASE_PASSWORD|unset}
  type: postgres
  username: ${DATABASE_USERNAME|postgres}
  url: ${DATABASE_URL|unset}

It would be great to have the behavior that Docker Compose provides to fail whenever a value for an environment variable is not present. Basically, if implemented exactly the same (bonus points!) the YAML file would be like this:

---
datasource:
  password: ${DATABASE_PASSWORD|?error}
  type: postgres
  username: ${DATABASE_USERNAME|postgres}
  url: ${DATABASE_URL|?error}
commented

hi @x80486 I added support for required value checking. Next version release.
e.g: ${DATABASE_URL|?error}

commented

hi @x80486 New version released