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"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
|
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]]
|
[[package]]
|
||||||
name = "atoi"
|
name = "atoi"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
|
@ -399,8 +410,10 @@ dependencies = [
|
||||||
"config",
|
"config",
|
||||||
"derive_builder",
|
"derive_builder",
|
||||||
"derive_more",
|
"derive_more",
|
||||||
|
"dummy_conductor",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
|
"libconductor",
|
||||||
"log",
|
"log",
|
||||||
"pretty_env_logger",
|
"pretty_env_logger",
|
||||||
"serde 1.0.145",
|
"serde 1.0.145",
|
||||||
|
@ -623,6 +636,16 @@ dependencies = [
|
||||||
"dirs",
|
"dirs",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dummy_conductor"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"async-trait",
|
||||||
|
"libconductor",
|
||||||
|
"serde 1.0.145",
|
||||||
|
"serde_json",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "either"
|
name = "either"
|
||||||
version = "1.8.0"
|
version = "1.8.0"
|
||||||
|
@ -969,6 +992,15 @@ version = "0.2.134"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "329c933548736bc49fd575ee68c89e8be4d260064184389a5b77517cddd99ffb"
|
checksum = "329c933548736bc49fd575ee68c89e8be4d260064184389a5b77517cddd99ffb"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libconductor"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"async-trait",
|
||||||
|
"serde 1.0.145",
|
||||||
|
"serde_json",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "linked-hash-map"
|
name = "linked-hash-map"
|
||||||
version = "0.5.6"
|
version = "0.5.6"
|
||||||
|
|
|
@ -25,6 +25,11 @@ url = { version = "2.2.2", features = ["serde"]}
|
||||||
serde_json = { version ="1", features = ["raw_value"]}
|
serde_json = { version ="1", features = ["raw_value"]}
|
||||||
clap = { vesrion = "3.2.20", features = ["derive"]}
|
clap = { vesrion = "3.2.20", features = ["derive"]}
|
||||||
|
|
||||||
|
[dependencies.libconductor]
|
||||||
|
path = "./env/libconductor"
|
||||||
|
|
||||||
|
[dependencies.dummy_conductor]
|
||||||
|
path = "./env/dummy_conductor"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
debug = true
|
debug = true
|
||||||
source_code = "https://git.batsense.net/librepages/conductor"
|
source_code = "https://git.batsense.net/librepages/conductor"
|
||||||
|
conductor = "dummy"
|
||||||
|
|
||||||
[server]
|
[server]
|
||||||
# Please set a unique value, your mCaptcha instance's security depends on this being
|
# 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.
|
//! App data: database connections, etc.
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use libconductor::Conductor;
|
||||||
|
|
||||||
//use crate::errors::ServiceResult;
|
//use crate::errors::ServiceResult;
|
||||||
use crate::settings::Settings;
|
use crate::settings::{ConductorType, Settings};
|
||||||
|
|
||||||
/// App data
|
/// App data
|
||||||
pub struct Ctx {
|
pub struct Ctx {
|
||||||
|
@ -26,6 +28,7 @@ pub struct Ctx {
|
||||||
/// app settings
|
/// app settings
|
||||||
pub settings: Settings,
|
pub settings: Settings,
|
||||||
pub source_code: String,
|
pub source_code: String,
|
||||||
|
pub conductor: Arc<Box<dyn Conductor>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Ctx {
|
impl Ctx {
|
||||||
|
@ -43,10 +46,21 @@ impl Ctx {
|
||||||
base.into()
|
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 {
|
let data = Ctx {
|
||||||
// db,
|
// db,
|
||||||
settings: s.clone(),
|
settings: s.clone(),
|
||||||
source_code,
|
source_code,
|
||||||
|
conductor,
|
||||||
};
|
};
|
||||||
|
|
||||||
Arc::new(data)
|
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)]
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
pub debug: bool,
|
pub debug: bool,
|
||||||
pub server: Server,
|
pub server: Server,
|
||||||
pub source_code: String,
|
pub source_code: String,
|
||||||
|
pub conductor: ConductorType,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(tarpaulin_include))]
|
#[cfg(not(tarpaulin_include))]
|
||||||
|
|
Loading…
Reference in a new issue