refactor: make everything a little more modular

This commit is contained in:
VC
2022-04-22 13:36:02 +02:00
parent de375b9f28
commit 080218f385
11 changed files with 478 additions and 323 deletions

51
src/config.rs Normal file
View File

@@ -0,0 +1,51 @@
// std
use std::fs::read_to_string;
// toml
use serde::Deserialize;
/// General configuration Struct
#[derive(Debug, Deserialize)]
pub struct Config {
pub twitter: TwitterConfig,
pub mastodon: MastodonConfig,
pub scootaloo: ScootalooConfig,
}
#[derive(Debug, Deserialize)]
pub struct TwitterConfig {
pub username: String,
pub consumer_key: String,
pub consumer_secret: String,
pub access_key: String,
pub access_secret: String,
}
#[derive(Debug, Deserialize)]
pub struct MastodonConfig {
pub base: String,
pub client_id: String,
pub client_secret: String,
pub redirect: String,
pub token: String,
}
#[derive(Debug, Deserialize)]
pub struct ScootalooConfig {
pub db_path: String,
pub cache_path: String,
}
/// Parses the TOML file into a Config Struct
pub fn parse_toml(toml_file: &str) -> Config {
let toml_config = read_to_string(toml_file).unwrap_or_else(|e|
panic!("Cannot open config file {}: {}", toml_file, e)
);
let config: Config = toml::from_str(&toml_config).unwrap_or_else(|e|
panic!("Cannot parse TOML file {}: {}", toml_file, e)
);
config
}