resolver trait

This commit is contained in:
mbecker20
2023-06-09 09:01:55 +00:00
parent 8ad84a8cec
commit fecc5134ad
6 changed files with 30 additions and 5 deletions

2
Cargo.lock generated
View File

@@ -1031,6 +1031,7 @@ name = "monitor_periphery"
version = "1.0.0"
dependencies = [
"anyhow",
"async-trait",
"async_timing_util",
"axum",
"bollard",
@@ -1055,6 +1056,7 @@ dependencies = [
name = "monitor_types"
version = "1.0.0"
dependencies = [
"async-trait",
"diff-struct",
"serde",
"strum",

View File

@@ -36,6 +36,7 @@ typeshare = "1.0.1"
strum = "0.24"
strum_macros = "0.24"
sysinfo = "0.29"
async-trait = "0.1"
# mogh
run_command = { version = "0.0.6", features = ["async_tokio"] }
slack = { package = "slack_client_rs", version = "0.0.8" }

View File

@@ -11,4 +11,5 @@ serde.workspace = true
diff-struct.workspace = true
typeshare.workspace = true
strum.workspace = true
strum_macros.workspace = true
strum_macros.workspace = true
async-trait.workspace = true

View File

@@ -1,11 +1,11 @@
use diff::Diff;
use serde::{Deserialize, Serialize, de::DeserializeOwned};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use strum_macros::{Display, EnumString};
use typeshare::typeshare;
pub mod core_api;
pub mod periphery_api;
pub mod entities;
pub mod periphery_api;
#[typeshare(serialized_as = "number")]
pub type I64 = i64;
@@ -138,6 +138,11 @@ pub trait HasResponse: Serialize + std::fmt::Debug {
fn req_type() -> &'static str;
}
#[async_trait::async_trait]
pub trait Resolve<Req: HasResponse> {
async fn resolve(&self, req: Req) -> Req::Response;
}
#[macro_export]
macro_rules! impl_has_response {
($req:ty, $res:ty) => {
@@ -148,4 +153,5 @@ macro_rules! impl_has_response {
}
}
};
}
}

View File

@@ -28,6 +28,7 @@ log.workspace = true
simple_logger.workspace = true
uuid.workspace = true
sysinfo.workspace = true
async-trait.workspace = true
# mogh
async_timing_util.workspace = true
merge_config_files.workspace = true

View File

@@ -1,5 +1,5 @@
use anyhow::{anyhow, Context};
use monitor_types::periphery_api::{requests::GetVersionResponse, PeripheryRequest};
use monitor_types::{periphery_api::{requests::{GetVersionResponse, GetHealth, GetHealthResponse, GetVersion}, PeripheryRequest}, Resolve};
use crate::state::State;
@@ -22,3 +22,17 @@ fn get_version() -> anyhow::Result<String> {
})
.context("failed to convert version to string")
}
#[async_trait::async_trait]
impl Resolve<GetHealth> for State {
async fn resolve(&self, _: GetHealth) -> GetHealthResponse {
GetHealthResponse {}
}
}
#[async_trait::async_trait]
impl Resolve<GetVersion> for State {
async fn resolve(&self, _: GetVersion) -> GetVersionResponse {
todo!()
}
}