Skip to content

Commit

Permalink
refactor: use top-level imports to simplify main
Browse files Browse the repository at this point in the history
Signed-off-by: Christina Sørensen <[email protected]>
  • Loading branch information
cafkafk committed Jun 21, 2024
1 parent 8aab582 commit af33a44
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use axum::{
routing::get,
Router,
};
use tokio::net::TcpListener;
use tokio::{net::TcpListener, sync::RwLock};

extern crate log;
extern crate pretty_env_logger;
Expand All @@ -29,7 +29,10 @@ use api::routes::get_routes as get_api_routes;
#[allow(unused)]
use log::{debug, error, info, trace, warn};

use crate::{data::status::ServerStatus, storage::s3::S3Backend};
use crate::{
data::{status::ServerStatus, Config},
storage::s3::S3Backend,
};

async fn handler_404() -> impl IntoResponse {
(StatusCode::NOT_FOUND, "404 - not found")
Expand All @@ -44,18 +47,14 @@ async fn main() -> Result<(), Box<dyn Error>> {
let config;

if let Some(path) = matches.get_one::<String>("init") {
crate::data::Config::gen_example_config(path)?;
Config::gen_example_config(path)?;
return Ok(());
}

if let Some(config_file) = matches.get_one::<String>("config") {
config = Arc::new(tokio::sync::RwLock::new(crate::data::Config::load(
config_file,
)));
config = Arc::new(RwLock::new(Config::load(config_file)));
} else {
config = Arc::new(tokio::sync::RwLock::new(crate::data::Config::load(
data::CONFIG,
)));
config = Arc::new(RwLock::new(Config::load(data::CONFIG)));
}

trace!("{config:#?}");
Expand Down

0 comments on commit af33a44

Please sign in to comment.