feat: load Conductor into
SUMMARY Conductor type is received from configuration file. Type is defined in src/settings.rs. ctx::Ctx initializes Conductor object based on the type specified in the configuration.
This commit is contained in:
parent
8908bd97e5
commit
6e70996f3f
5 changed files with 62 additions and 1 deletions
32
Cargo.lock
generated
32
Cargo.lock
generated
|
@ -240,6 +240,17 @@ version = "0.5.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
|
||||
|
||||
[[package]]
|
||||
name = "async-trait"
|
||||
version = "0.1.57"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "76464446b8bc32758d7e88ee1a804d9914cd9b1cb264c029899680b0be29826f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atoi"
|
||||
version = "1.0.0"
|
||||
|
@ -399,8 +410,10 @@ dependencies = [
|
|||
"config",
|
||||
"derive_builder",
|
||||
"derive_more",
|
||||
"dummy_conductor",
|
||||
"futures-util",
|
||||
"lazy_static",
|
||||
"libconductor",
|
||||
"log",
|
||||
"pretty_env_logger",
|
||||
"serde 1.0.145",
|
||||
|
@ -623,6 +636,16 @@ dependencies = [
|
|||
"dirs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dummy_conductor"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"libconductor",
|
||||
"serde 1.0.145",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.8.0"
|
||||
|
@ -969,6 +992,15 @@ version = "0.2.134"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "329c933548736bc49fd575ee68c89e8be4d260064184389a5b77517cddd99ffb"
|
||||
|
||||
[[package]]
|
||||
name = "libconductor"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"serde 1.0.145",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linked-hash-map"
|
||||
version = "0.5.6"
|
||||
|
|
|
@ -25,6 +25,11 @@ url = { version = "2.2.2", features = ["serde"]}
|
|||
serde_json = { version ="1", features = ["raw_value"]}
|
||||
clap = { vesrion = "3.2.20", features = ["derive"]}
|
||||
|
||||
[dependencies.libconductor]
|
||||
path = "./env/libconductor"
|
||||
|
||||
[dependencies.dummy_conductor]
|
||||
path = "./env/dummy_conductor"
|
||||
|
||||
[build-dependencies]
|
||||
serde_json = "1"
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
debug = true
|
||||
source_code = "https://git.batsense.net/librepages/conductor"
|
||||
conductor = "dummy"
|
||||
|
||||
[server]
|
||||
# Please set a unique value, your mCaptcha instance's security depends on this being
|
||||
|
|
16
src/ctx.rs
16
src/ctx.rs
|
@ -16,8 +16,10 @@
|
|||
//! App data: database connections, etc.
|
||||
use std::sync::Arc;
|
||||
|
||||
use libconductor::Conductor;
|
||||
|
||||
//use crate::errors::ServiceResult;
|
||||
use crate::settings::Settings;
|
||||
use crate::settings::{ConductorType, Settings};
|
||||
|
||||
/// App data
|
||||
pub struct Ctx {
|
||||
|
@ -26,6 +28,7 @@ pub struct Ctx {
|
|||
/// app settings
|
||||
pub settings: Settings,
|
||||
pub source_code: String,
|
||||
pub conductor: Arc<Box<dyn Conductor>>,
|
||||
}
|
||||
|
||||
impl Ctx {
|
||||
|
@ -43,10 +46,21 @@ impl Ctx {
|
|||
base.into()
|
||||
};
|
||||
|
||||
let conductor: Box<dyn Conductor> = match s.conductor {
|
||||
ConductorType::Dummy => {
|
||||
use dummy_conductor::DummyConductor;
|
||||
|
||||
Box::new(DummyConductor {})
|
||||
}
|
||||
};
|
||||
|
||||
let conductor = Arc::new(conductor);
|
||||
|
||||
let data = Ctx {
|
||||
// db,
|
||||
settings: s.clone(),
|
||||
source_code,
|
||||
conductor,
|
||||
};
|
||||
|
||||
Arc::new(data)
|
||||
|
|
|
@ -40,11 +40,20 @@ impl Server {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Display, Eq, PartialEq, Clone, Debug)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum ConductorType {
|
||||
/// doesn't do anything
|
||||
#[display(fmt = "dummy")]
|
||||
Dummy,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct Settings {
|
||||
pub debug: bool,
|
||||
pub server: Server,
|
||||
pub source_code: String,
|
||||
pub conductor: ConductorType,
|
||||
}
|
||||
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
|
|
Loading…
Reference in a new issue