31 lines
788 B
Rust
31 lines
788 B
Rust
use std::fs::File;
|
|
use std::io::BufReader;
|
|
use std::error::Error;
|
|
use std::path::Path;
|
|
use serde::{Deserialize};
|
|
use lazy_static::lazy_static;
|
|
|
|
#[allow(non_snake_case)]
|
|
#[derive(Deserialize)]
|
|
pub struct Config {
|
|
pub DURATION: u64,
|
|
pub STATION_ID: usize,
|
|
pub HOST: String,
|
|
pub WSS_HOST: String,
|
|
}
|
|
|
|
fn read_config_from_file<P: AsRef<Path>>(path: P) -> Result<Config, Box<dyn Error>> {
|
|
// Open the file in read-only mode with buffer.
|
|
let file = File::open(path)?;
|
|
let reader = BufReader::new(file);
|
|
|
|
// Read the JSON contents of the file as an instance of `User`.
|
|
let config = serde_json::from_reader(reader)?;
|
|
|
|
// Return the `User`.
|
|
Ok(config)
|
|
}
|
|
|
|
lazy_static! {
|
|
pub static ref CONFIG: Config = read_config_from_file("config.json").unwrap();
|
|
} |