summaryrefslogtreecommitdiff
path: root/common/rust/src
diff options
context:
space:
mode:
authorMatthieu <matthieu@developershouse.xyz>2021-10-02 16:40:48 +0400
committerMatthieu <matthieu@developershouse.xyz>2021-10-02 16:40:48 +0400
commit4a08838b902d7f7c0c4daec5fe121707d794ec6e (patch)
tree0f5b2f71c16dd1c0f320a3ed54c0540f7d1913cc /common/rust/src
parentb36eca5b9fc32d22820f2a08bd935d66b6e856c2 (diff)
fix: unable to set nested variables
Diffstat (limited to 'common/rust/src')
-rw-r--r--common/rust/src/config.rs14
1 files changed, 9 insertions, 5 deletions
diff --git a/common/rust/src/config.rs b/common/rust/src/config.rs
index c158a21..d4437a9 100644
--- a/common/rust/src/config.rs
+++ b/common/rust/src/config.rs
@@ -1,9 +1,8 @@
use std::env;
-use config::{Config, ConfigError, Environment, File};
+use config::{Config, ConfigError, Environment, File, Source};
use log::info;
-use serde::{Deserialize};
-
+use serde::Deserialize;
#[derive(Debug, Deserialize, Clone)]
#[serde(bound(deserialize = "T: Deserialize<'de> + std::default::Default + Clone"))]
@@ -14,7 +13,10 @@ pub struct Settings<T> {
pub nats: crate::nats::NatsConfiguration,
}
-impl<T> Settings<T> where T: Deserialize<'static> + std::default::Default + Clone {
+impl<T> Settings<T>
+where
+ T: Deserialize<'static> + std::default::Default + Clone,
+{
pub fn new(service_name: &str) -> Result<Settings<T>, ConfigError> {
let mut default = Config::default();
// this file my be shared with all the components
@@ -25,8 +27,10 @@ impl<T> Settings<T> where T: Deserialize<'static> + std::default::Default + Clon
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("__");
+ println!("{:?}", env.collect());
// 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