cdb/src/config.rs

32 lines
786 B
Rust
Raw Normal View History

2024-09-08 00:37:39 +00:00
use serde::Deserialize;
2024-09-12 09:54:52 +00:00
#[derive(Debug, Default, Clone, Deserialize)]
2024-09-08 00:37:39 +00:00
pub struct Config {
/// Allowed tokens for access
pub allowed_tokens: Vec<String>,
2024-09-12 09:48:09 +00:00
/// Webhook Config
pub webhook: Option<Webhook>,
2024-09-08 00:37:39 +00:00
}
pub fn get_config() -> Config {
if let Ok(content) = std::fs::read_to_string("./config.toml") {
return toml::from_str(&content).unwrap();
}
Config::default()
}
2024-09-12 09:48:09 +00:00
#[derive(Debug, Clone, Deserialize)]
pub struct Webhook {
pub item_below_minimum: Option<String>,
pub transaction_added: Option<String>,
pub transaction_consumed: Option<String>,
}
impl Webhook {
pub async fn send(url: &str, data: &serde_json::Value) {
let client = reqwest::Client::new();
client.post(url).json(data).send().await.unwrap();
}
}