conductor/src/ctx.rs

57 lines
1.7 KiB
Rust

/*
* Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
//! App data: database connections, etc.
use std::sync::Arc;
//use crate::errors::ServiceResult;
use crate::settings::Settings;
/// App data
pub struct Ctx {
// /// database ops defined by db crates
// pub db: BoxDB,
/// app settings
pub settings: Settings,
pub source_code: String,
}
impl Ctx {
#[cfg(not(tarpaulin_include))]
/// create new instance of app data
pub async fn new(s: &Settings) -> ArcCtx {
let source_code = {
let mut url = s.source_code.clone();
if !url.ends_with('/') {
url.push('/');
}
let mut base = url::Url::parse(&url).unwrap();
base = base.join("tree/").unwrap();
base = base.join(crate::GIT_COMMIT_HASH).unwrap();
base.into()
};
let data = Ctx {
// db,
settings: s.clone(),
source_code,
};
Arc::new(data)
}
}
pub type ArcCtx = Arc<Ctx>;