Add .env loading when the app starts. - #36
Merged
Conversation
Add a new env module with load_env/ load_env_from that loads variables from a .env file using dotenvy. Loading is best-effort: a missing file is logged at debug level and is not treated as an error. Called in main() after init_logger and before CLI parsing. - Add dotenvy dependency, create src/env.rs with tests via TDD - Call load_env() in marketdata.rs after init_logger() - Add .env to .gitignore, document in config.toml - Create ADR-012, update AGENTS.md
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.
Resolves #35
Changes
Add best-effort
.envfile loading at application startup using thedotenvycrate.src/env.rsmodule:load_env()loads.envfrom the current directory;load_env_from(path)enables testing with temp directories. Missing file = debug log (no error). Present file = info log. Never panics.src/bin/marketdata.rs: callsload_env()immediately afterinit_logger()and before CLI parsing / config file reading.Cargo.toml: addsdotenvyandtempfile(dev-dependency)..gitignore: adds.enventry (was only.env.local).config.toml: documents.envloading and credential precedence.envmodule.Testing
src/env.rs(TDD: tests written first, then implementation): verifies a present.envpopulates env vars and a missing file does not panic.Precedence
explicit env var > .env file > config.toml —
dotenvyonly sets vars not already in the environment, and config.toml values take precedence over env vars (ADR-011).