kkyr/fig

Add a strict parsing alternative which disallows unknown fields

arieltorti opened this issue · 0 comments

It would be nice to have something akin to json.DisallowUnknownFields and yaml.UnmarshalStrict to catch configuration invalid configurations earlier and make them an error.

I propose to add a new flag fig.UseStrict, when set fig.Load will return an error upon encountering unknown (i.e: extra) fields.

For example. given:

---
log_level: debug
host: "0.0.0.0"
type Config struct {
	Host string `fig:"host"`
	LogLevel string `fig:"logLevel"`
}

var cfg Server
fig.Load(&cfg, UseStrict()) // Returns error because the key `log_level` is unknown