From a02b25f235ba6eff33c6fd965c97071d5f112b6d Mon Sep 17 00:00:00 2001 From: Matthieu Date: Fri, 8 Oct 2021 14:48:39 +0400 Subject: changes in the proto names, and new spec for nats --- common/rust/src/config.rs | 8 +++++++- common/rust/src/lib.rs | 6 +++--- common/rust/src/nats.rs | 1 - common/rust/src/payloads.rs | 23 +++++++++++++++++------ 4 files changed, 27 insertions(+), 11 deletions(-) (limited to 'common/rust/src') diff --git a/common/rust/src/config.rs b/common/rust/src/config.rs index d4437a9..3dcd72c 100644 --- a/common/rust/src/config.rs +++ b/common/rust/src/config.rs @@ -1,9 +1,12 @@ use std::env; - use config::{Config, ConfigError, Environment, File, Source}; use log::info; use serde::Deserialize; +/// Settings is the base structure for all the nova's component config +/// you can specify a type T and the name of the component. the "config" +/// field will be equals to the key named after the given component name +/// and will be of type T #[derive(Debug, Deserialize, Clone)] #[serde(bound(deserialize = "T: Deserialize<'de> + std::default::Default + Clone"))] pub struct Settings { @@ -13,10 +16,13 @@ pub struct Settings { pub nats: crate::nats::NatsConfiguration, } +/// impl Settings where T: Deserialize<'static> + std::default::Default + Clone, { + /// Initializes a new configuration like the other components of nova + /// And starts the prometheus metrics server if needed. pub fn new(service_name: &str) -> Result, ConfigError> { let mut default = Config::default(); // this file my be shared with all the components diff --git a/common/rust/src/lib.rs b/common/rust/src/lib.rs index 943d7cc..1125f5a 100644 --- a/common/rust/src/lib.rs +++ b/common/rust/src/lib.rs @@ -1,7 +1,7 @@ -/// This crate contains shared code in all the rust projects -/// It contains utilities such as monitoring, logging and more. +/// This crate is all the utilities shared by the nova rust projects +/// It includes loging, config and protocols. pub mod config; pub mod monitoring; pub mod nats; pub mod payloads; -pub mod error; \ No newline at end of file +pub mod error; diff --git a/common/rust/src/nats.rs b/common/rust/src/nats.rs index 59b480c..437a857 100644 --- a/common/rust/src/nats.rs +++ b/common/rust/src/nats.rs @@ -24,7 +24,6 @@ pub struct NatsConfiguration { host: String, } -/// impl Into for NatsConfiguration { fn into(self) -> Connection { let mut options = Options::new(); diff --git a/common/rust/src/payloads.rs b/common/rust/src/payloads.rs index 6eb35c8..2da70e3 100644 --- a/common/rust/src/payloads.rs +++ b/common/rust/src/payloads.rs @@ -1,15 +1,26 @@ use serde::{Deserialize, Serialize}; +use std::fmt::Debug; -/// Payload send to the nova cache queues -#[derive(Serialize, Deserialize, Debug, Clone)] -#[serde(bound(deserialize = "T: Deserialize<'de> + std::default::Default + Clone"))] + + +/// Data structure sent to the cache component +/// by the gateway & webhook. +#[derive(Serialize, Deserialize, Debug)] +#[serde(bound(deserialize = "T: Deserialize<'de> + Debug"))] pub struct CachePayload { + + #[serde(rename = "tr")] pub tracing: Tracing, - pub data: T + + #[serde(rename = "d")] + pub data: T, + + #[serde(rename = "o")] + pub operation: String, } -#[derive(Serialize, Deserialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Debug)] pub struct Tracing { pub node_id: String, pub span: Option -} \ No newline at end of file +} -- cgit v1.2.3