Initial commit
This commit is contained in:
commit
f67dcd8f2a
31 changed files with 3297 additions and 0 deletions
65
src/cfg.rs
Normal file
65
src/cfg.rs
Normal file
|
@ -0,0 +1,65 @@
|
|||
use std::{fs, net::SocketAddr, path::PathBuf};
|
||||
|
||||
use eyre::Context;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Http {
|
||||
pub listen: SocketAddr,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum LogLevel {
|
||||
Info,
|
||||
Debug,
|
||||
// Error, // there's no error logs.
|
||||
Off,
|
||||
}
|
||||
|
||||
impl From<LogLevel> for Option<tracing::Level> {
|
||||
fn from(value: LogLevel) -> Self {
|
||||
use tracing::Level as L;
|
||||
|
||||
Some(match value {
|
||||
LogLevel::Info => L::INFO,
|
||||
LogLevel::Debug => L::DEBUG,
|
||||
LogLevel::Off => return None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(untagged, rename_all = "snake_case")]
|
||||
pub enum Secret {
|
||||
Path { path: PathBuf },
|
||||
Plain(String),
|
||||
}
|
||||
|
||||
impl Secret {
|
||||
pub fn into_string(&self) -> eyre::Result<String> {
|
||||
match self {
|
||||
Self::Path { path } => fs::read_to_string(path).wrap_err("failed to read secret"),
|
||||
Self::Plain(s) => Ok(s.clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct App {
|
||||
pub secret: Secret,
|
||||
|
||||
pub log_level: LogLevel,
|
||||
pub journal: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Journal {
|
||||
pub root: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Root {
|
||||
pub app: App,
|
||||
pub http: Http,
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue