more config stuff

This commit is contained in:
s1idewhist1e 2023-05-08 09:25:31 -07:00
parent ce685af31a
commit 92fcfc1a08
No known key found for this signature in database
GPG key ID: 9CC756BB9B325062
3 changed files with 107 additions and 4 deletions

View file

@ -112,7 +112,7 @@ mod tests {
assert_eq!(
config,
Config {
url: String::from("https://example.tld/"),
url: Host("https://example.tld/".into()),
port: 3000,
db: db::DbConfig {
host: String::from("localhost"),

View file

@ -1,11 +1,51 @@
use serde::Deserialize;
type Port = u16;
#[derive(Debug, PartialEq, Deserialize)]
pub struct MaxNoteLength(pub u16);
#[derive(Debug, PartialEq, Deserialize)]
pub enum IpFamily {
Both = 0,
IPv4 = 4,
IPv6 = 6,
}
#[derive(Debug, PartialEq, Deserialize, Default)]
pub struct Host(pub String);
#[derive(Debug, PartialEq, Deserialize)]
#[serde(rename = "camelCase")]
pub struct Config {
pub url: String,
pub port: u16,
pub url: Host,
pub port: Port,
pub db: db::DbConfig,
pub redis: redis::RedisConfig,
pub sonic: sonic::SonicConfig,
pub elasticsearch: elasticsearch::ElasticsearchConfig,
pub id: IdGenerator,
pub max_note_length: MaxNoteLength,
pub max_caption_length: MaxNoteLength,
pub disable_hsts: bool,
pub cluster_limit: u16,
pub deliver_job_concurrency: u16,
pub inbox_job_concurrency: u16,
pub deliver_job_per_sec: u16,
pub inbox_job_per_sec: u16,
pub deliver_job_max_attempts: u16,
pub inbox_job_max_attempts: u16,
pub outgoing_address_family: IpFamily,
pub syslog: syslog::SyslogConfig,
pub proxy: Host,
}
#[derive(Debug, PartialEq, Deserialize)]
pub enum IdGenerator {
AId,
MeId,
ULId,
ObjectID,
}
pub mod db {
@ -14,7 +54,7 @@ pub mod db {
#[serde(rename = "camelCase")]
pub struct DbConfig {
pub host: String,
pub port: u16,
pub port: Port,
pub db: String,
pub user: String,
pub pass: String,
@ -30,6 +70,64 @@ pub mod db {
}
}
pub mod redis {
use super::*;
#[derive(Debug, PartialEq, Deserialize)]
#[serde(rename = "camelCase")]
pub struct RedisConfig {
pub host: String,
pub port: Port,
#[serde(default = "ip_family_fn")]
pub family: IpFamily,
#[serde(default)]
pub pass: Option<String>,
#[serde(default)]
pub prefix: Option<String>,
#[serde(default)]
pub db: Option<i32>,
}
}
pub mod sonic {
use super::*;
#[derive(Debug, PartialEq, Deserialize)]
pub struct SonicConfig {
pub host: Host,
pub port: Port,
pub auth: String,
pub collection: String,
pub bucket: Option<String>,
}
}
pub mod elasticsearch {
use super::*;
#[derive(Debug, PartialEq, Deserialize)]
pub struct ElasticsearchConfig {
pub host: Host,
pub port: Port,
#[serde(default)]
pub ssl: bool,
pub user: Option<String>,
pub pass: Option<String>,
}
}
pub mod syslog {
use super::*;
#[derive(Debug, PartialEq, Deserialize)]
pub struct SyslogConfig {}
}
fn true_fn() -> bool {
true
}
fn ip_family_fn() -> IpFamily {
IpFamily::Both
}

View file

@ -1,3 +1,6 @@
use std::path::Path;
mod config;
fn main() {
@ -6,4 +9,6 @@ fn main() {
// ENV
// get config
config::init_config(Path::new(""));
}