Fix coding style issue

This commit is contained in:
Pierre HUBERT 2022-03-30 08:42:18 +02:00
parent b4e8113706
commit 6d8b8979ca
2 changed files with 23 additions and 13 deletions

View File

@ -30,6 +30,10 @@ impl<E> EntityManager<E> where E: rocket::serde::Serialize + rocket::serde::Dese
self.list.len()
}
pub fn is_empty(&self) -> bool {
self.len() == 0
}
/// Save the list
fn save(&self) -> Res {
Ok(std::fs::write(&self.file_path, serde_json::to_string(&self.list)?)?)

View File

@ -13,8 +13,8 @@ fn index() -> &'static str {
"Running"
}
#[launch]
fn rocket() -> _ {
#[rocket::main]
async fn main() -> Result<(), rocket::Error> {
//env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
let rocket = rocket::build()
@ -26,7 +26,10 @@ fn rocket() -> _ {
let config: AppConfig = figment.extract().expect("config");
if !config.storage_path().exists() {
log::error!("Specified storage path {:?} does not exists!", config.storage_path());
log::error!(
"Specified storage path {:?} does not exists!",
config.storage_path()
);
panic!()
}
@ -34,18 +37,21 @@ fn rocket() -> _ {
.expect("Failed to load users list!");
// Create initial user if required
if users.len() == 0 {
if users.is_empty() {
log::info!("Create default {} user", DEFAULT_ADMIN_USERNAME);
let mut default_admin = User::default();
default_admin.username = DEFAULT_ADMIN_USERNAME.to_string();
default_admin.password = hash_password(DEFAULT_ADMIN_PASSWORD).unwrap();
default_admin.need_reset_password = true;
default_admin.authorized_services = None;
default_admin.admin = true;
let default_admin = User {
username: DEFAULT_ADMIN_USERNAME.to_string(),
password: hash_password(DEFAULT_ADMIN_PASSWORD).unwrap(),
need_reset_password: true,
authorized_services: None,
admin: true,
..Default::default()
};
users.insert(default_admin)
users
.insert(default_admin)
.expect("Failed to create initial user!");
}
rocket
}
rocket.launch().await
}