style: format code for consistency and readability

This commit is contained in:
DamonXue
2025-03-02 20:06:45 +08:00
parent 6660b048a1
commit f2929fd2ee
4 changed files with 24 additions and 23 deletions
+9 -5
View File
@@ -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();
}
+5 -6
View File
@@ -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)
}
}
+8 -10
View File
@@ -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<Request<()>, 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();
+2 -2
View File
@@ -5,6 +5,6 @@ pub(crate) fn get_local_ip() -> Option<std::net::Ipv4Addr> {
match local_ip_address::local_ip() {
Ok(IpAddr::V4(ip)) => Some(ip),
Err(_) => None,
Ok(IpAddr::V6(_)) => todo!()
Ok(IpAddr::V6(_)) => todo!(),
}
}
}