Skip to content

Commit 87bbfc2

Browse files
author
Chris Connelly
committed
chore: add basic configuration handling
Currently, this will read configuration from environment variables only. The `envy` library can attempt to deserialize any struct implementing `serde::Deserialize` from environment variables, which is pretty neat.
1 parent a3f8ccd commit 87bbfc2

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

Cargo.lock

Lines changed: 15 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ edition = "2021"
77

88
[dependencies]
99
axum = "0.4.2"
10+
envy = "0.4.2"
1011
juniper = "0.15.7"
1112
juniper_hyper = "0.8.0"
1213
parking_lot = "0.11.2"
14+
serde = { version = "1.0.131", features = ["derive"] }
1315
tokio = { version = "1.14.0", features = ["macros", "rt-multi-thread"] }
1416
tower = "0.4.11"
1517
tower-http = { version = "0.2.0", features = ["trace"] }

src/main.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,25 @@ use axum::{
1414
use juniper::{EmptySubscription, RootNode};
1515
use tower::ServiceBuilder;
1616
use tower_http::trace::TraceLayer;
17-
use tracing::info;
17+
use tracing::{info, trace};
1818
use tracing_subscriber::EnvFilter;
1919

2020
use self::graphql::{Context, Mutation, Query};
2121

22+
#[derive(Debug, serde::Deserialize)]
23+
struct Config {
24+
database_url: String,
25+
}
26+
2227
#[tokio::main]
2328
async fn main() {
2429
tracing_subscriber::fmt()
2530
.with_env_filter(EnvFilter::from_default_env())
2631
.init();
2732

33+
let config: Config = envy::from_env().unwrap();
34+
trace!("TODO: connect to {}", config.database_url);
35+
2836
let context = Arc::new(Context::default());
2937
let root_node = Arc::new(RootNode::new(Query, Mutation, EmptySubscription::new()));
3038

0 commit comments

Comments
 (0)