Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a strict parsing alternative which disallows unknown fields #18

Closed
arieltorti opened this issue Mar 16, 2023 · 0 comments · Fixed by #19
Closed

Add a strict parsing alternative which disallows unknown fields #18

arieltorti opened this issue Mar 16, 2023 · 0 comments · Fixed by #19

Comments

@arieltorti
Copy link
Contributor

arieltorti commented Mar 16, 2023

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant