2023-06-03 15:52:29 +00:00
|
|
|
use config::Config;
|
|
|
|
use serde::Deserialize;
|
|
|
|
|
2023-06-03 16:54:41 +00:00
|
|
|
#[derive(Deserialize, Debug)]
|
2023-06-03 15:52:29 +00:00
|
|
|
pub enum DacFamily {
|
|
|
|
Helios,
|
2023-06-03 16:54:41 +00:00
|
|
|
Etherdream,
|
|
|
|
}
|
2023-06-03 15:52:29 +00:00
|
|
|
|
2023-06-03 16:54:41 +00:00
|
|
|
#[derive(Deserialize, Debug)]
|
2023-06-03 16:11:55 +00:00
|
|
|
pub struct Conf {
|
2023-06-03 21:27:12 +00:00
|
|
|
pub laser_id: u8,
|
|
|
|
pub debug: bool,
|
|
|
|
pub redis_url: String,
|
|
|
|
pub dac_family: DacFamily,
|
|
|
|
pub dac_id: Option<u8>,
|
|
|
|
pub dac_url: Option<String>,
|
2023-06-03 15:52:29 +00:00
|
|
|
}
|
2023-06-03 16:54:41 +00:00
|
|
|
pub fn load_config(path: &str) -> Result<Conf, Box<dyn std::error::Error>> {
|
2023-06-03 16:11:55 +00:00
|
|
|
let settings = Config::builder()
|
|
|
|
.add_source(config::File::with_name(path))
|
|
|
|
.build()?;
|
2023-06-03 15:52:29 +00:00
|
|
|
|
2023-06-04 09:28:43 +00:00
|
|
|
let conf : Conf = settings.try_deserialize()?;
|
2023-06-03 15:52:29 +00:00
|
|
|
Ok(conf)
|
2023-06-03 16:11:55 +00:00
|
|
|
}
|