PoC in Rust not working sending /api/station/register

This commit is contained in:
Martin Quarda
2025-05-10 10:29:55 +02:00
parent 2e84b06a91
commit 1957ff7f9f
7 changed files with 178 additions and 3 deletions

33
POC_in_rust/src/config.rs Normal file
View 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();
}