summaryrefslogtreecommitdiff
path: root/common/rust/src/config.rs
diff options
context:
space:
mode:
authorn1c00o <34602094+n1c00o@users.noreply.github.com>2021-10-16 22:26:09 +0200
committerGitHub <noreply@github.com>2021-10-16 22:26:09 +0200
commite58e816ceb8caa3c77dd98a952761b7e7f05b6cb (patch)
treeca5c9409986ff538e7a674473c1d642627d1055c /common/rust/src/config.rs
parent03908129599260587fe7b9fd8254d28ad50b8714 (diff)
parentb94b0552f81e667bec31352901bbc8c76f1b4216 (diff)
Merge branch 'main' into nats-structs-discord-gateway
Diffstat (limited to 'common/rust/src/config.rs')
-rw-r--r--common/rust/src/config.rs22
1 files changed, 19 insertions, 3 deletions
diff --git a/common/rust/src/config.rs b/common/rust/src/config.rs
index bd12350..327f6f8 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};
use log::info;
use serde::Deserialize;
+/// Settings<T> 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<T> {
@@ -11,13 +14,20 @@ pub struct Settings<T> {
pub config: T,
pub monitoring: crate::monitoring::MonitoringConfiguration,
pub nats: crate::nats::NatsConfiguration,
+ pub redis: crate::redis::RedisConfiguration,
}
+///
impl<T> Settings<T>
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<Settings<T>, ConfigError> {
+ pretty_env_logger::init();
+
let mut default = Config::default();
// this file my be shared with all the components
default.merge(File::with_name("config/default"))?;
@@ -27,16 +37,22 @@ where
default.merge(File::with_name(&format!("config/{}", mode)).required(false))?;
default.merge(File::with_name("config/local").required(false))?;
+ let env = Environment::with_prefix("NOVA").separator("__");
// we can configure each component using environment variables
- default.merge(Environment::with_prefix("NOVA").separator("_"))?;
+ default.merge(env)?;
let mut config: Settings<T> = default.clone().try_into().unwrap();
// try to load the config
config.config = default.get::<T>(service_name).unwrap();
- pretty_env_logger::init();
+ // todo(MatthieuCodder): the following line was not present in the conflict
+ // pretty_env_logger::init();
// start the monitoring system if needed
crate::monitoring::start_monitoring(&config.monitoring);
Ok(config)
}
}
+
+pub fn test_init() {
+ pretty_env_logger::init();
+}