Skip to content

Commit 25a614d

Browse files
authored
Add ability to pull environment variables from a .env file (#39)
1 parent c3fb8e1 commit 25a614d

File tree

5 files changed

+7
-0
lines changed

5 files changed

+7
-0
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ thiserror = "1.0.31"
3030
anyhow = "1.0.57"
3131

3232
lazy_static = "1.4.0"
33+
dotenv = "0.15.0"
3334

3435
[dependencies.sqlx]
3536
version = "0.5.13"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ environment variable.
3939
#### Environment Variables
4040
A few things can also be configured via environment variables.
4141
Generally most things that can be configured via an environment variable can also be configured via the config file.
42+
Shorty will also look for a .env file in the same directory it's executed from and pull environment variables from there.
4243

4344
`SHORTY_CONFIG` was mentioned before. With it you can set a custom location for the config file.
4445
By default shorty will look for the config file in the current folder. This can obviously not be configured

src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ pub enum ShortyError {
1818
#[error(transparent)]
1919
Database(#[from] sqlx::Error),
2020
#[error(transparent)]
21+
Dotenv(#[from] dotenv::Error),
22+
#[error(transparent)]
2123
Other(#[from] anyhow::Error),
2224
}
2325

src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ async fn get_favicon() -> Result<impl Responder, ShortyError> {
139139

140140
#[tokio::main]
141141
async fn main() -> Result<(), ShortyError> {
142+
dotenv::dotenv()?;
143+
142144
let env_filter = EnvFilter::from_default_env()
143145
.add_directive(Level::INFO.into())
144146
.add_directive("shorty=debug".parse().unwrap());

0 commit comments

Comments
 (0)