use std::fs::File;
use std::io::prelude::*;
use serde::{Deserialize, Serialize};
#[cfg(not(tarpaulin_include))]
pub fn parse(filepath: String) -> Result<Config, String> {
let mut file =
File::open(filepath.as_str()).unwrap_or_else(|_| panic!("error opening file - {filepath}"));
let mut contents = String::new();
file.read_to_string(&mut contents)
.unwrap_or_else(|_| panic!("error reading file - {filepath}"));
let parsed_config: Config = serde_yaml::from_str(&contents)
.unwrap_or_else(|_| panic!("error parsing file - {filepath}"));
Ok(parsed_config)
}
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct Config {
pub items: Option<Vec<String>>,
pub lang: Option<String>,
pub logging: Option<Logging>,
pub server: Option<Server>,
pub client: Option<Client>,
}
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct Logging {
pub level: u8,
pub file: String,
}
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct Client {
pub port: u16,
pub addr: String,
}
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct Server {
pub port: u16,
pub addr: String,
pub tls: Option<TLS>,
}
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct TLS {
pub cert: String,
pub key: String,
}