Files
Raid_Manager/lib/src/main.rs

42 lines
1.0 KiB
Rust
Raw Normal View History

2022-12-04 15:02:07 +01:00
#[macro_use]
extern crate rocket;
mod parser;
#[cfg(feature = "static")]
mod embed;
use rocket::error::ErrorKind;
2022-12-04 15:02:07 +01:00
use rocket::serde::json::Json;
#[cfg(feature = "static")]
use crate::embed::CustomHandler;
2022-12-05 23:18:32 +01:00
use crate::parser::lsblk_parser::{Disk, parse_lsblk};
2022-12-05 00:03:22 +01:00
use crate::parser::mdstat_parser::{MdRaidSystem, parse_mdstat};
2022-12-04 15:02:07 +01:00
#[get("/raiddevices")]
fn get_raid_devices() -> Json<MdRaidSystem> {
Json(parse_mdstat())
}
2022-12-05 23:18:32 +01:00
#[get("/disks")]
fn get_disks() -> Json<Vec<Disk>> {
Json(parse_lsblk())
}
2022-12-04 15:02:07 +01:00
#[rocket::main]
async fn main() -> Result<(), rocket::Error> {
println!("init server");
println!("access at: http://127.0.0.1:8000/");
let b = rocket::build();
let b = b.mount("/api", routes![get_raid_devices, get_disks]);
#[cfg(feature = "static")]
let b = b.mount("/", CustomHandler{});
if let Err(_rocket) = b.launch().await {
match _rocket.kind() {
ErrorKind::Bind(_) => println!("Bind address already in use!"),
e => println!("{}", e.to_string())
}
}
2022-12-04 15:02:07 +01:00
Ok(())
2022-12-06 22:22:24 +01:00
}