diff options
| author | Joe Carstairs <me@joeac.net> | 2026-09-04 18:50:53 +0100 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2026-09-04 18:50:53 +0100 |
| commit | 5270c5c73fc9e843b922f1e12b81c3c78d7e8a26 (patch) | |
| tree | 864ee1f5fd962e87a2ca7690b22974fc24068a3d /src/config.rs | |
| parent | d6426030b3572545a58234a780b94e746135f13b (diff) | |
config file from arg or default location
Diffstat (limited to 'src/config.rs')
| -rw-r--r-- | src/config.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..518a82a --- /dev/null +++ b/src/config.rs @@ -0,0 +1,30 @@ +use std::{fs::File, io::{Read, read_to_string}, path::Path}; + +use serde::Deserialize; + +#[derive(Deserialize)] +pub struct Config { +} + +pub const DEFAULT_CONFIG_FILE_LOCATIONS: [&str; 1] = [ + "/etc/rss-aggregator.toml", +]; + +impl Config { + pub fn parse_config_file_at_path(path: &str) -> anyhow::Result<Config> { + let path = Path::new(path); + let file = File::open(&path)?; + let contents = read_to_string(file)?; + Ok(toml::from_str(&contents)?) + } + + pub fn find_config() -> Option<Config> { + for path in DEFAULT_CONFIG_FILE_LOCATIONS { + match Self::parse_config_file_at_path(path) { + Ok(config) => { return Some(config); }, + Err(_) => {}, + }; + }; + None + } +} |
