Skip to content
Snippets Groups Projects
config.rs 556 B
Newer Older
Stephen D's avatar
Stephen D committed
use serde::Deserialize;
use std::fs;

#[derive(Deserialize)]
pub struct Config {
	pub(crate) token: String,
}

pub fn get_conf() -> Config {
	let file_contents = read_conf_file();
	match toml::from_str(&file_contents) {
		Ok(x) => x,
		Err(x) => {
			panic!("Error parsing config file: {}", x);
		}
	}
}

fn read_conf_file() -> String {
	let filenames = ["config.toml", "/etc/cat_disruptor_6500/config.toml"];
	for filename in filenames.iter() {
		if let Ok(x) = fs::read_to_string(filename) {
			return x;
		}
	}

	panic!("Could not open config file");
}