Skip to content

feat: config to override env vars #341

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

Merged
merged 6 commits into from
Jun 30, 2025
Merged

Conversation

nickajacks1
Copy link
Contributor

Add a config option to env provider to allow users to change the source of environment variables. Doing so is particularly useful in parallel tests where t.Setenv will not work.

@knadh
Copy link
Owner

knadh commented Mar 6, 2025

This breaks the API and backwards compatibility. I suggest that we refactor this into a breaking github.com/knadh/koanf/providers/env/v2 version.

@nickajacks1
Copy link
Contributor Author

nickajacks1 commented Mar 6, 2025

Are you sure it's a breaking change? I tried to make it compatible by making it a variadic parameter. I'm OK with updating this to make a v2 if you prefer, though.

@knadh
Copy link
Owner

knadh commented Mar 7, 2025

Ah, my bad. Missed the variadic bit. Let me test this out next week. Thank you.

@knadh
Copy link
Owner

knadh commented Mar 13, 2025

I think we might as well break to /v2 and remove the awkward ProviderWithValue() func in the process.

func Provider(prefix, delim string, opt Opt{}, cb func(key string, value string) (string, interface{})) *Env

@nickajacks1
Copy link
Contributor Author

Sounds good, I'll update soon

@nickajacks1
Copy link
Contributor Author

Should we stuff the callback and the prefix in Opt while we're at it since they're technically optional?

@knadh
Copy link
Owner

knadh commented Mar 14, 2025

Yep, we can do that.

@nickajacks1
Copy link
Contributor Author

Updated for v2. Unfortunately, examples/go.mod can't be updated until v2 is pushed (unless we add replace directives).

@knadh
Copy link
Owner

knadh commented Apr 15, 2025

examples can be a separate commit, no issues. Could you please merge conflict and rebase with master (min required Go version throughout the project is now v1.23.0)? Also, need to update the env references in the README.

@nickajacks1
Copy link
Contributor Author

Rebased. Apologies for asking you to hold my hand, but could you point out where in the README I missed updating the references to env? I thought I got everything.

@knadh knadh self-assigned this Apr 16, 2025
@nickajacks1
Copy link
Contributor Author

Friendly ping

@knadh
Copy link
Owner

knadh commented Jun 25, 2025

Ah, lost track of this. Will review and merge this week.

nickajacks1 and others added 5 commits June 29, 2025 11:30
Make a breaking change to the env.Provider function to use an Option
struct to allow future extensions without breaking changes. Merge both
transformation callbacks into a single callback.

Add a config option to allow users to change the source of environment
variables. Doing so is particularly useful in parallel tests where
t.Setenv will not work.
- Removed the superfluous `..Opt` variadic argument.
- Simplify `Provider()` init.
- Improve comments.
- Switch to the `f()` pattern with an arg struct for better readability.
- Add new test for non-string param value.
@knadh
Copy link
Owner

knadh commented Jun 29, 2025

Reviewed and added a few commits with minor cosmetic improvements and updated your branch. Please take a look and confirm, and then we're good to merge.

@nickajacks1
Copy link
Contributor Author

Everything looks good to me, thanks!

@knadh knadh merged commit 8161a16 into knadh:master Jun 30, 2025
2 checks passed
@nickajacks1 nickajacks1 deleted the envp-opts branch June 30, 2025 11:52
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 this pull request may close these issues.

2 participants