Conversation
Since fig relies on mapstructure, fields can be annotated
with `",squash"` to flatten the config. It's super helpful
for base settings that are embedded.
However, because the environment variable resolution relies
on field.path(), it doesn't match the config-file structure.
This makes field.path() omit squashed fields.
Example config that's affected:
```yml
env: prod
logging:
level: info
```
Example structs:
```go
type Base struct {
Env string `fig:"env"`
Logging struct {
Level string `fig:"level"`
} `fig:"logging"`
}
type Config struct {
Base `fig:",squash"`
}
```
Overriding with env var before and after this change:
```bash
BASE_ENV=staging # before
ENV=staging # after
```
kkyr
reviewed
May 3, 2025
Contributor
Author
|
@kkyr Done! |
Contributor
Author
|
@kkyr Friendly ping here when you have time. :) |
Owner
|
Merged! Apologies for getting to this so late |
Owner
|
Available on v0.5.0 |
Contributor
Author
|
@kkyr All good! You're already way better at replying to PRs and issues than I am. :) Thanks a bunch ❤️ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
(previous PR based from master vs. my branch)
Since fig relies on mapstructure, fields can be annotated with
",squash"to flatten the config. It's super helpful for base settings that are embedded.However, because the environment variable resolution relies on field.path(), it doesn't match the config-file structure.
This makes field.path() omit squashed fields.
Example config that's affected:
Example structs:
Overriding with env var before and after this change:
Test Plan