From f2929fd2eebee5111792a58d260f35282e13f38a Mon Sep 17 00:00:00 2001 From: DamonXue Date: Sun, 2 Mar 2025 20:06:45 +0800 Subject: [PATCH] style: format code for consistency and readability --- rustfs/src/console.rs | 14 +++++++++----- rustfs/src/macro/mod.rs | 11 +++++------ rustfs/src/main.rs | 18 ++++++++---------- rustfs/src/utils.rs | 4 ++-- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/rustfs/src/console.rs b/rustfs/src/console.rs index 161d6725b..f6a28b491 100644 --- a/rustfs/src/console.rs +++ b/rustfs/src/console.rs @@ -53,7 +53,7 @@ pub(crate) struct Config { s3: S3, release: Release, license: License, - doc: String + doc: String, } impl Config { @@ -74,7 +74,7 @@ impl Config { name: "Apache-2.0".to_string(), url: "https://www.apache.org/licenses/LICENSE-2.0".to_string(), }, - doc: "https://rustfs.com/docs/".to_string() + doc: "https://rustfs.com/docs/".to_string(), } } @@ -162,10 +162,14 @@ pub async fn start_static_file_server(addrs: &str, local_ip: Ipv4Addr, access_ke let listener = tokio::net::TcpListener::bind(addrs).await.unwrap(); let local_addr = listener.local_addr().unwrap(); - timed_println!(format!("WebUI: http://{}:{} http://127.0.0.1:{}", - local_ip, local_addr.port(), local_addr.port())); + timed_println!(format!( + "WebUI: http://{}:{} http://127.0.0.1:{}", + local_ip, + local_addr.port(), + local_addr.port() + )); timed_println!(format!(" RootUser: {}", access_key)); timed_println!(format!(" RootPass: {}", secret_key)); - + axum::serve(listener, app).await.unwrap(); } diff --git a/rustfs/src/macro/mod.rs b/rustfs/src/macro/mod.rs index fe08915f9..21f6da521 100644 --- a/rustfs/src/macro/mod.rs +++ b/rustfs/src/macro/mod.rs @@ -6,7 +6,7 @@ use syn::{parse_macro_input, Expr, LitStr}; pub fn timed_println(input: TokenStream) -> TokenStream { // 解析输入 let expr = parse_macro_input!(input as Expr); - + // 生成带有时间戳的打印代码 let expanded = quote! { { @@ -15,17 +15,16 @@ pub fn timed_println(input: TokenStream) -> TokenStream { println!("{} rustfs: {}", timestamp, #expr); } }; - + TokenStream::from(expanded) } - #[proc_macro] pub fn timed_println_str(input: TokenStream) -> TokenStream { // 尝试将输入解析为字符串字面量 let input_str = parse_macro_input!(input as LitStr); let str_value = input_str.value(); - + // 生成带有时间戳的打印代码 let expanded = quote! { { @@ -34,6 +33,6 @@ pub fn timed_println_str(input: TokenStream) -> TokenStream { println!("{} rustfs: {}", timestamp, #str_value); } }; - + TokenStream::from(expanded) -} \ No newline at end of file +} diff --git a/rustfs/src/main.rs b/rustfs/src/main.rs index d5e43aa70..d97866daa 100644 --- a/rustfs/src/main.rs +++ b/rustfs/src/main.rs @@ -13,6 +13,7 @@ use rustfs_macro::timed_println; use crate::auth::IAMAuth; use crate::console::{init_console_cfg, CONSOLE_CONFIG}; +use chrono::Datelike; use clap::Parser; use common::{ error::{Error, Result}, @@ -44,15 +45,13 @@ use tokio::net::TcpListener; use tonic::{metadata::MetadataValue, Request, Status}; use tower_http::cors::CorsLayer; use tracing::{debug, error, info, warn}; -use chrono::Datelike; use tracing_error::ErrorLayer; use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt}; fn setup_tracing() { use tracing_subscriber::EnvFilter; - let env_filter = EnvFilter::try_from_default_env() - .unwrap_or_else(|_| EnvFilter::new("info")); + let env_filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")); let enable_color = std::io::stdout().is_terminal(); let subscriber = fmt() @@ -80,7 +79,7 @@ fn check_auth(req: Request<()>) -> Result, Status> { fn print_server_info() { let cfg = CONSOLE_CONFIG.get().unwrap(); let current_year = chrono::Utc::now().year(); - + // 使用过程宏打印服务器信息 timed_println!("RustFS Object Storage Server"); timed_println!(format!("Copyright: 2024-{} RustFS, Inc", current_year)); @@ -135,14 +134,14 @@ async fn run(opt: config::Opt) -> Result<()> { for (i, eps) in endpoint_pools.as_ref().iter().enumerate() { info!( "Formatting {}st pool, {} set(s), {} drives per set.", - i + 1, eps.set_count, eps.drives_per_set + i + 1, + eps.set_count, + eps.drives_per_set ); - + // Add warning for host with multiple drives in a set (similar to RustFS) if eps.drives_per_set > 1 { - warn!( - "WARNING: Host local has more than 0 drives of set. A host failure will result in data becoming unavailable." - ); + warn!("WARNING: Host local has more than 0 drives of set. A host failure will result in data becoming unavailable."); } } @@ -291,7 +290,6 @@ async fn run(opt: config::Opt) -> Result<()> { init_console_cfg(&srv_addr); print_server_info(); - if opt.console_enable { debug!("console is enabled"); let access_key = opt.access_key.clone(); diff --git a/rustfs/src/utils.rs b/rustfs/src/utils.rs index 0ac4ab7a0..24afba86a 100644 --- a/rustfs/src/utils.rs +++ b/rustfs/src/utils.rs @@ -5,6 +5,6 @@ pub(crate) fn get_local_ip() -> Option { match local_ip_address::local_ip() { Ok(IpAddr::V4(ip)) => Some(ip), Err(_) => None, - Ok(IpAddr::V6(_)) => todo!() + Ok(IpAddr::V6(_)) => todo!(), } -} \ No newline at end of file +}