mirror of
https://git.alemi.dev/guestbook.rs.git
synced 2024-11-10 02:39:18 +01:00
chore: tweaked config structure
This commit is contained in:
parent
4078963c9e
commit
b424579002
2 changed files with 13 additions and 8 deletions
|
@ -4,7 +4,7 @@
|
|||
pub struct Config {
|
||||
pub overrides: ConfigOverrides,
|
||||
|
||||
pub notifiers: Vec<ConfigNotifier>,
|
||||
pub notifiers: ConfigNotifiers,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
|
||||
|
@ -16,8 +16,13 @@ pub struct ConfigOverrides {
|
|||
pub date: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
|
||||
pub struct ConfigNotifiers {
|
||||
pub providers: Vec<ConfigNotifierProvider>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub enum ConfigNotifier {
|
||||
pub enum ConfigNotifierProvider {
|
||||
ConsoleNotifier,
|
||||
|
||||
#[cfg(feature = "telegram")]
|
||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -1,7 +1,7 @@
|
|||
use std::net::SocketAddr;
|
||||
use clap::{Parser, Subcommand};
|
||||
|
||||
use crate::{storage::JsonFileStorageStrategy, routes::Context, notifications::console::ConsoleTracingNotifier, config::{Config, ConfigNotifier}};
|
||||
use crate::{storage::JsonFileStorageStrategy, routes::Context, notifications::console::ConsoleTracingNotifier, config::{Config, ConfigNotifierProvider}};
|
||||
|
||||
mod notifications;
|
||||
|
||||
|
@ -59,9 +59,9 @@ async fn main() {
|
|||
match args.action {
|
||||
CliAction::Default => {
|
||||
let mut cfg = Config::default();
|
||||
cfg.notifiers.push(ConfigNotifier::ConsoleNotifier);
|
||||
cfg.notifiers.providers.push(ConfigNotifierProvider::ConsoleNotifier);
|
||||
#[cfg(feature = "telegram")]
|
||||
cfg.notifiers.push(ConfigNotifier::TelegramNotifier { token: "asd".into(), chat_id: -1 });
|
||||
cfg.notifiers.providers.push(ConfigNotifierProvider::TelegramNotifier { token: "asd".into(), chat_id: -1 });
|
||||
println!("{}", toml::to_string(&cfg).unwrap());
|
||||
},
|
||||
CliAction::Serve { addr, config } => {
|
||||
|
@ -77,14 +77,14 @@ async fn main() {
|
|||
|
||||
let mut state = Context::new(storage, config.overrides);
|
||||
|
||||
for notifier in config.notifiers {
|
||||
for notifier in config.notifiers.providers {
|
||||
match notifier {
|
||||
ConfigNotifier::ConsoleNotifier => {
|
||||
ConfigNotifierProvider::ConsoleNotifier => {
|
||||
state.register(Box::new(ConsoleTracingNotifier {}));
|
||||
},
|
||||
|
||||
#[cfg(feature = "telegram")]
|
||||
ConfigNotifier::TelegramNotifier { token, chat_id } => {
|
||||
ConfigNotifierProvider::TelegramNotifier { token, chat_id } => {
|
||||
state.register(Box::new(
|
||||
notifications::telegram::TGNotifier::new(&token, chat_id)
|
||||
));
|
||||
|
|
Loading…
Reference in a new issue