lighthouse-pulse/lighthouse/config/mod.rs

34 lines
904 B
Rust
Raw Normal View History

2018-09-21 21:45:40 +00:00
extern crate dirs;
use std::fs;
use std::path::PathBuf;
2018-08-06 23:13:24 +00:00
2018-08-23 05:11:15 +00:00
/// Stores the core configuration for this Lighthouse instance.
/// This struct is general, other components may implement more
/// specialized config structs.
2018-08-06 23:13:24 +00:00
#[derive(Clone)]
pub struct LighthouseConfig {
pub data_dir: PathBuf,
2018-08-07 00:08:39 +00:00
pub p2p_listen_port: u16,
2018-08-06 23:13:24 +00:00
}
const DEFAULT_LIGHTHOUSE_DIR: &str = ".lighthouse";
impl LighthouseConfig {
/// Build a new lighthouse configuration from defaults.
pub fn default() -> Self{
let data_dir = {
2018-09-21 21:45:40 +00:00
let home = dirs::home_dir()
2018-08-06 23:13:24 +00:00
.expect("Unable to determine home dir.");
home.join(DEFAULT_LIGHTHOUSE_DIR)
};
2018-08-23 05:11:15 +00:00
fs::create_dir_all(&data_dir)
2018-09-21 22:17:31 +00:00
.unwrap_or_else(|_| panic!("Unable to create {:?}", &data_dir));
2018-08-07 00:08:39 +00:00
let p2p_listen_port = 0;
2018-08-06 23:13:24 +00:00
Self {
data_dir,
p2p_listen_port,
}
}
}