PoC in Rust not working sending /api/station/register
This commit is contained in:
33
POC_in_rust/src/config.rs
Normal file
33
POC_in_rust/src/config.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
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 SAVING_INTERVAL: u64,
|
||||
pub STATION_ID: usize,
|
||||
pub HOST: String,
|
||||
pub LOGIN: String,
|
||||
pub PASSWORD: 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();
|
||||
}
|
||||
Reference in New Issue
Block a user