use crate::client::name_generator::NameGenerator;
use crate::proxy_error::ProxyResult;
use serde::{Deserialize, Serialize};
use std::fs::File;
use std::path::PathBuf;
#[derive(Serialize, Deserialize)]
pub struct Config {
pub users_file_path: String,
pub core_host: String,
pub proxy_url: String,
pub client_id: String,
}
impl Config {
pub fn initialize(file: PathBuf) -> ProxyResult<Self> {
if !file.exists() {
let file = File::create(file.clone())?;
serde_yaml::to_writer(file, &Self::default())?;
}
Self::load_from_file(file)
}
fn load_from_file(file: PathBuf) -> ProxyResult<Self> {
let file = File::open(file)?;
Ok(serde_yaml::from_reader(file)?)
}
}
impl Default for Config {
fn default() -> Self {
Self {
users_file_path: String::from("resources/users.yaml"),
core_host: String::from("http://127.0.0.1:5354"),
proxy_url: String::from("wss://proxy.new-home.yannik-sc.de:13370"),
client_id: NameGenerator::new().generate_name(2),
}
}
}