Add server initialisation

This commit is contained in:
Andras Schmelczer 2024-12-08 11:02:34 +00:00
parent c2dceb0be4
commit 01f0c873a9
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
2 changed files with 46 additions and 0 deletions

View file

@ -0,0 +1,19 @@
use crate::{config::Config, consts::CONFIG_PATH, database::Database};
use anyhow::Result;
#[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(path).await?;
let database = Database::try_new(&config.database).await?;
Ok(Self { config, database })
}
}