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() self.list.len()
} }
pub fn is_empty(&self) -> bool {
self.len() == 0
}
/// Save the list /// Save the list
fn save(&self) -> Res { fn save(&self) -> Res {
Ok(std::fs::write(&self.file_path, serde_json::to_string(&self.list)?)?) Ok(std::fs::write(&self.file_path, serde_json::to_string(&self.list)?)?)

View File

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