From c34aab6ac842f3cc1d56bce224c1b355ff4e5be0 Mon Sep 17 00:00:00 2001 From: s1idewhist1e Date: Tue, 9 May 2023 22:06:08 -0700 Subject: [PATCH] more config initialization --- packages/backend/.gitignore | 2 +- packages/backend/crates/config/src/data.rs | 18 +++++++++++++++--- packages/backend/crates/config/src/lib.rs | 8 ++++++-- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/packages/backend/.gitignore b/packages/backend/.gitignore index c4653682cf..7846ed4262 100644 --- a/packages/backend/.gitignore +++ b/packages/backend/.gitignore @@ -1,4 +1,4 @@ -# +# profiling data *.profraw *.profdata diff --git a/packages/backend/crates/config/src/data.rs b/packages/backend/crates/config/src/data.rs index 9cca4d3f15..8553f21858 100644 --- a/packages/backend/crates/config/src/data.rs +++ b/packages/backend/crates/config/src/data.rs @@ -1,4 +1,4 @@ -use serde::{de::Visitor, Deserialize}; +use serde::Deserialize; type Port = u16; @@ -22,6 +22,7 @@ impl<'de> Deserialize<'de> for IpFamily { { struct IpFamilyVisitor; + use serde::de::Visitor; impl<'de> Visitor<'de> for IpFamilyVisitor { type Value = IpFamily; @@ -61,6 +62,7 @@ impl<'de> Deserialize<'de> for Host { { struct HostVisitor; + use serde::de::Visitor; impl<'de> Visitor<'de> for HostVisitor { type Value = Host; @@ -135,6 +137,8 @@ pub struct Config { // pub email: Option, // pub object_storage: Option, // pub summaly_proxy_url: Option, + #[serde(skip)] + pub env: env::Environment, } #[derive(Debug, PartialEq, Deserialize)] @@ -171,8 +175,8 @@ pub mod db { impl Default for Extra { fn default() -> Self { - Self { ssl: true } - } + Self { ssl: true } + } } } @@ -246,6 +250,14 @@ pub mod twa { pub struct TWAConfig {} } +/// Environment variables set when initialized +pub mod env { + use super::*; + + #[derive(Debug, PartialEq, Deserialize, Default)] + pub struct Environment {} +} + impl Default for MaxNoteLength { fn default() -> Self { Self(3000) diff --git a/packages/backend/crates/config/src/lib.rs b/packages/backend/crates/config/src/lib.rs index fa79f8d34e..e825137f47 100644 --- a/packages/backend/crates/config/src/lib.rs +++ b/packages/backend/crates/config/src/lib.rs @@ -3,6 +3,7 @@ use std::fs::File; use std::io::{self, Read}; use std::path::Path; +use data::env::Environment; use once_cell::sync::OnceCell; mod data; @@ -59,7 +60,9 @@ fn fetch_config(path: &Path) -> Result { static CONFIG: OnceCell = OnceCell::new(); pub fn init_config(cfg_path: &Path) -> Result<(), Error> { - let config = fetch_config(cfg_path)?; + let mut config = fetch_config(cfg_path)?; + config.env = Environment {}; + CONFIG.get_or_init(move || config); Ok(()) } @@ -149,7 +152,8 @@ redis: }, max_note_length: MaxNoteLength(3000), max_caption_length: MaxCommentLength(1500), - cluster_limit: None + cluster_limit: None, + env: Environment { }, } ); }