-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.rs
39 lines (32 loc) · 1.01 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#![forbid(unsafe_code)]
use std::process;
use emojied::db;
use emojied::state::AppState;
use emojied::config::AppConfig;
#[tokio::main]
async fn main() {
println!("Loading configuration from environment");
let config = AppConfig::from_env().unwrap_or_else(|err| {
eprintln!("Application config error: {}", err);
process::exit(1);
});
println!("Attempting to establish a database connection");
match db::Handle::new(config.clone()).await {
Ok(db_handle) => {
eprintln!("Database connection established");
let state = AppState {
config,
db_handle,
};
// https://docs.rs/axum/0.4.8/axum/extract/struct.Extension.html
if let Err(e) = emojied::run(state).await {
eprintln!("Application error: {}", e);
process::exit(1);
}
}
Err(e) => {
eprintln!("Database error: {:#?}", e);
process::exit(1);
}
};
}