mirror of
https://framagit.org/veretcle/tootube.git
synced 2025-07-21 13:24:19 +02:00
Initial commit
This commit is contained in:
31
src/config.rs
Normal file
31
src/config.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use std::fs::read_to_string;
|
||||
|
||||
use serde::Deserialize;
|
||||
|
||||
// General configuration Struct
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Config {
|
||||
pub peertube: PeertubeConfig,
|
||||
pub youtube: YoutubeConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct PeertubeConfig {
|
||||
pub base_url: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct YoutubeConfig {
|
||||
pub api_key: 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 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
|
||||
}
|
Reference in New Issue
Block a user