more config initialization
This commit is contained in:
parent
d61fd0f418
commit
c34aab6ac8
3 changed files with 22 additions and 6 deletions
2
packages/backend/.gitignore
vendored
2
packages/backend/.gitignore
vendored
|
@ -1,4 +1,4 @@
|
|||
#
|
||||
# profiling data
|
||||
*.profraw
|
||||
*.profdata
|
||||
|
||||
|
|
|
@ -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)]
|
||||
|
@ -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)
|
||||
|
|
|
@ -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 { },
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue