Move app state
This commit is contained in:
parent
cd7fe5fe39
commit
0943681702
7 changed files with 15 additions and 20 deletions
20
backend/sync_server/src/server/app_state.rs
Normal file
20
backend/sync_server/src/server/app_state.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
use anyhow::Result;
|
||||
|
||||
use crate::{config::Config, consts::CONFIG_PATH, database::Database};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct AppState {
|
||||
pub config: Config,
|
||||
pub database: Database,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
pub async fn try_new() -> Result<Self> {
|
||||
let path = std::path::Path::new(CONFIG_PATH);
|
||||
|
||||
let config = Config::read_or_create(path).await?;
|
||||
let database = Database::try_new(&config.database).await?;
|
||||
|
||||
Ok(Self { config, database })
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue