-
-
Notifications
You must be signed in to change notification settings - Fork 112
Description
Hi @alexflint, love this project and I think it's super complete, thanks so much for providing such a helpful library.
We've been using caarlos0/env previously and loved its ability to auto-infer the name of environment variables from the struct field name (e.g. AuthKey becomes AUTH_KEY), as it helps us stay DRY and avoid hard-to-debug issues where someone renames the field but forgets to update the env tag (or vice versa) and configuration doesn't get parsed correctly. Your library is a lot more complete and we'd love to migrate to it, but would love to support "auto-env" tags first (happy to work on an implementation if you think this is something that would get merged).
I was thinking we could either provide a new boolean in the Config struct, something like AutoEnv, which would pre-populate spec.env here if enabled, or perhaps provide a Config.envName func(fieldName string) string that allows users to define any function they want to map a field name to an env name (this way we could remain backwards-compatible and default to strings.ToUpper like you do here). As a reference, here's the function I'd like to provide for this mapping: https://github.com/caarlos0/env/blob/main/env.go#L516-L533
Again, thanks so much for such a comprehensive library!