more config initialization

This commit is contained in:
s1idewhist1e 2023-05-09 22:06:08 -07:00
parent d61fd0f418
commit c34aab6ac8
No known key found for this signature in database
GPG key ID: 9CC756BB9B325062
3 changed files with 22 additions and 6 deletions

View file

@ -1,4 +1,4 @@
#
# profiling data
*.profraw
*.profdata

View file

@ -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<email::Email>,
// pub object_storage: Option<object_storage::ObjectStorageConfig>,
// pub summaly_proxy_url: Option<Host>,
#[serde(skip)]
pub env: env::Environment,
}
#[derive(Debug, PartialEq, Deserialize)]
@ -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)

View file

@ -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<Config, Error> {
static CONFIG: OnceCell<Config> = 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 { },
}
);
}