diff --git a/client/build.rs b/client/build.rs index 3958bc91..1448ee84 100644 --- a/client/build.rs +++ b/client/build.rs @@ -38,5 +38,5 @@ fn main() { rustc_version().unwrap() ); } - println!("cargo:rustc-env=APP_VERSION={}", app_version); + println!("cargo:rustc-env=APP_VERSION={app_version}"); } diff --git a/client/src/grpc.rs b/client/src/grpc.rs index 214b48c9..0b2884fc 100644 --- a/client/src/grpc.rs +++ b/client/src/grpc.rs @@ -11,9 +11,8 @@ use stat_common::server_status::StatRequest; use crate::sample_all; use crate::Args; -use crate::INTERVAL_MS; -// TODO TLS +// TODO mTLS pub async fn report(args: &Args, stat_base: &mut StatRequest) -> anyhow::Result<()> { if !vec![stat_base.online4, stat_base.online6].iter().any(|&x| x) { @@ -68,6 +67,6 @@ pub async fn report(args: &Args, stat_base: &mut StatRequest) -> anyhow::Result< } }); - thread::sleep(Duration::from_millis(INTERVAL_MS)); + thread::sleep(Duration::from_secs(args.report_interval)); } } diff --git a/client/src/vnstat.rs b/client/src/vnstat.rs index 218d97aa..debff3f9 100644 --- a/client/src/vnstat.rs +++ b/client/src/vnstat.rs @@ -161,7 +161,7 @@ pub fn get_traffic(args: &Args) -> Result<(u64, u64, u64, u64)> { let b = str::from_utf8(&a)?; let j: VnstatJson = serde_json::from_str(b).unwrap_or_else(|e| { error!("{:?}", e); - panic!("invalid vnstat json `{}", b) + panic!("invalid vnstat json `{b}") }); calc_traffic(j, false, args) } else if args.vnstat_mr > 1 && args.vnstat_mr <= 28 { @@ -174,7 +174,7 @@ pub fn get_traffic(args: &Args) -> Result<(u64, u64, u64, u64)> { let b = str::from_utf8(&a)?; let j: VnstatJson = serde_json::from_str(b).unwrap_or_else(|e| { error!("{:?}", e); - panic!("invalid vnstat json `{}", b) + panic!("invalid vnstat json `{b}") }); calc_traffic(j, true, args) } else { diff --git a/common/build.rs b/common/build.rs index ae9c0cec..5b958af6 100644 --- a/common/build.rs +++ b/common/build.rs @@ -20,7 +20,7 @@ fn main() { Utc::now().format("%Y-%m-%d %H:%M:%S %Z") ); } - println!("cargo:rustc-env=APP_VERSION={}", app_version); + println!("cargo:rustc-env=APP_VERSION={app_version}"); std::env::set_var("PROTOC", protobuf_src::protoc()); tonic_build::configure() diff --git a/server/build.rs b/server/build.rs index 3958bc91..1448ee84 100644 --- a/server/build.rs +++ b/server/build.rs @@ -38,5 +38,5 @@ fn main() { rustc_version().unwrap() ); } - println!("cargo:rustc-env=APP_VERSION={}", app_version); + println!("cargo:rustc-env=APP_VERSION={app_version}"); } diff --git a/server/src/grpc.rs b/server/src/grpc.rs index de8a44e6..578b4d32 100644 --- a/server/src/grpc.rs +++ b/server/src/grpc.rs @@ -66,7 +66,7 @@ fn check_auth(req: Request<()>) -> Result, Status> { pub async fn serv_grpc(addr: &str) -> anyhow::Result<()> { let sock_addr = addr.parse().unwrap(); let sss = ServerStatusSrv::default(); - eprintln!("🚀 listening on grpc://{}", sock_addr); + eprintln!("🚀 listening on grpc://{sock_addr}"); let svc = ServerStatusServer::with_interceptor(sss, check_auth); Server::builder() .add_service(svc) diff --git a/server/src/http.rs b/server/src/http.rs index 2d7c0156..832b697c 100644 --- a/server/src/http.rs +++ b/server/src/http.rs @@ -144,7 +144,7 @@ pub async fn init_client(req: Request) -> Result> { domain = host.to_string(); }) }); - server_url = format!("{}://{}/report", scheme, domain); + server_url = format!("{scheme}://{domain}/report"); } let debug = params.get("debug").map(|p| p.eq("1")).unwrap_or(false); @@ -175,7 +175,7 @@ pub async fn init_client(req: Request) -> Result> { let exclude_iface = params.get("exclude-iface").unwrap_or(&invalid); // build client opts - let mut client_opts = format!(r#"-a "{}" -p "{}""#, server_url, pass); + let mut client_opts = format!(r#"-a "{server_url}" -p "{pass}""#); if debug { client_opts.push_str(" -d"); } @@ -183,7 +183,7 @@ pub async fn init_client(req: Request) -> Result> { client_opts.push_str(" -n"); } if 1 < vnstat_mr && vnstat_mr <= 28 { - let _ = write!(client_opts, r#" --vnstat-mr {}"#, vnstat_mr); + let _ = write!(client_opts, r#" --vnstat-mr {vnstat_mr}"#); } if disable_ping { client_opts.push_str(" --disable-ping"); @@ -195,39 +195,39 @@ pub async fn init_client(req: Request) -> Result> { client_opts.push_str(" --disable-extra"); } if weight > 0 { - let _ = write!(client_opts, r#" -w {}"#, weight); + let _ = write!(client_opts, r#" -w {weight}"#); } if !gid.is_empty() { - let _ = write!(client_opts, r#" -g "{}""#, gid); - let _ = write!(client_opts, r#" --alias "{}""#, alias); + let _ = write!(client_opts, r#" -g "{gid}""#); + let _ = write!(client_opts, r#" --alias "{alias}""#); } if !uid.is_empty() { - let _ = write!(client_opts, r#" -u "{}""#, uid); + let _ = write!(client_opts, r#" -u "{uid}""#); } if !notify { client_opts.push_str(" --disable-notify"); } if !host_type.is_empty() { - let _ = write!(client_opts, r#" -t "{}""#, host_type); + let _ = write!(client_opts, r#" -t "{host_type}""#); } if !location.is_empty() { - let _ = write!(client_opts, r#" --location "{}""#, location); + let _ = write!(client_opts, r#" --location "{location}""#); } - if !cm.is_empty() && cm.contains(":") { - let _ = write!(client_opts, r#" --cm "{}""#, cm); + if !cm.is_empty() && cm.contains(':') { + let _ = write!(client_opts, r#" --cm "{cm}""#); } - if !ct.is_empty() && ct.contains(":") { - let _ = write!(client_opts, r#" --ct "{}""#, ct); + if !ct.is_empty() && ct.contains(':') { + let _ = write!(client_opts, r#" --ct "{ct}""#); } - if !cu.is_empty() && cu.contains(":") { - let _ = write!(client_opts, r#" --cu "{}""#, cu); + if !cu.is_empty() && cu.contains(':') { + let _ = write!(client_opts, r#" --cu "{cu}""#); } if !iface.is_empty() { - let _ = write!(client_opts, r#" --iface "{}""#, iface); + let _ = write!(client_opts, r#" --iface "{iface}""#); } if !exclude_iface.is_empty() { - let _ = write!(client_opts, r#" --exclude-iface "{}""#, exclude_iface); + let _ = write!(client_opts, r#" --exclude-iface "{exclude_iface}""#); } Ok(jinja::render_template( @@ -326,16 +326,16 @@ pub async fn get_detail(req: Request) -> Result> { .as_ref() .map(|o| { let mut s = String::new(); - s.push_str(format!("version: {}\n", o.version).as_str()); - s.push_str(format!("host_name: {}\n", o.host_name).as_str()); - s.push_str(format!("os_name: {}\n", o.os_name).as_str()); - s.push_str(format!("os_arch: {}\n", o.os_arch).as_str()); - s.push_str(format!("os_family: {}\n", o.os_family).as_str()); - s.push_str(format!("os_release: {}\n", o.os_release).as_str()); - s.push_str(format!("kernel_version: {}\n", o.kernel_version).as_str()); - s.push_str(format!("cpu_num: {}\n", o.cpu_num).as_str()); - s.push_str(format!("cpu_brand: {}\n", o.cpu_brand).as_str()); - s.push_str(format!("cpu_vender_id: {}", o.cpu_vender_id).as_str()); + s.push_str(&format!("version: {}\n", o.version)); + s.push_str(&format!("host_name: {}\n", o.host_name)); + s.push_str(&format!("os_name: {}\n", o.os_name)); + s.push_str(&format!("os_arch: {}\n", o.os_arch)); + s.push_str(&format!("os_family: {}\n", o.os_family)); + s.push_str(&format!("os_release: {}\n", o.os_release)); + s.push_str(&format!("kernel_version: {}\n", o.kernel_version)); + s.push_str(&format!("cpu_num: {}\n", o.cpu_num)); + s.push_str(&format!("cpu_brand: {}\n", o.cpu_brand)); + s.push_str(&format!("cpu_vender_id: {}", o.cpu_vender_id)); s }) .unwrap_or_default(); @@ -372,7 +372,7 @@ pub async fn get_detail(req: Request) -> Result> { host.uptime_str, ip_info.query, sys_info, - format!("{}\n{}", addrs, isp) + format!("{addrs}\n{isp}") ]); } else { table.add_row(row![ diff --git a/server/src/jinja.rs b/server/src/jinja.rs index 3666520d..8b09d1c7 100644 --- a/server/src/jinja.rs +++ b/server/src/jinja.rs @@ -11,7 +11,7 @@ where T: Into + std::fmt::Display, S: Into, { - let name = format!("{}.{}", kind, tag); + let name = format!("{kind}.{tag}"); JINJA_ENV .lock() .as_mut() @@ -24,7 +24,7 @@ where } pub fn render_template<'a>(kind: &'a str, tag: &'a str, ctx: Value, trim: bool) -> Result { - let name = format!("{}.{}", kind, tag); + let name = format!("{kind}.{tag}"); Ok(JINJA_ENV .lock() .map(|e| { diff --git a/server/src/main.rs b/server/src/main.rs index e31514ac..cd663cf6 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -255,11 +255,11 @@ async fn main() -> Result<()> { let http_service = make_service_fn(|_| async { Ok::<_, GenericError>(service_fn(main_service_func)) }); let http_addr = G_CONFIG.get().unwrap().http_addr.parse()?; - eprintln!("🚀 listening on http://{}", http_addr); + eprintln!("🚀 listening on http://{http_addr}"); let server = Server::bind(&http_addr).serve(http_service); let graceful = server.with_graceful_shutdown(shutdown_signal()); if let Err(e) = graceful.await { - eprintln!("server error: {}", e); + eprintln!("server error: {e}"); } Ok(()) diff --git a/server/src/notifier/log.rs b/server/src/notifier/log.rs index d46605f3..7d3d398d 100644 --- a/server/src/notifier/log.rs +++ b/server/src/notifier/log.rs @@ -48,7 +48,7 @@ impl crate::notifier::Notifier for Log { let dt = Local::now().format("%Y-%m-%d").to_string(); let log_file = Path::new(&self.config.log_dir) - .join(format!("ssr.log.{}", dt)) + .join(format!("ssr.log.{dt}")) .to_string_lossy() .to_string(); @@ -61,23 +61,23 @@ impl crate::notifier::Notifier for Log { .append(true) .open(&log_file) .await - .unwrap_or_else(|_| panic!("can't create log `{}", log_file)); + .unwrap_or_else(|_| panic!("can't create log `{log_file}")); let _ = file .write(content.as_bytes()) .await - .unwrap_or_else(|_| panic!("can't write log `{}", log_file)); + .unwrap_or_else(|_| panic!("can't write log `{log_file}")); if !content.ends_with('\n') { let _ = file .write(b"\n") .await - .unwrap_or_else(|_| panic!("can't write log `{}", log_file)); + .unwrap_or_else(|_| panic!("can't write log `{log_file}")); } file.flush() .await - .unwrap_or_else(|_| panic!("can't flush log `{}", log_file)); + .unwrap_or_else(|_| panic!("can't flush log `{log_file}")); }); Ok(()) } diff --git a/server/src/notifier/webhook.rs b/server/src/notifier/webhook.rs index eb73d91d..f25a2e9e 100644 --- a/server/src/notifier/webhook.rs +++ b/server/src/notifier/webhook.rs @@ -68,9 +68,8 @@ impl Webhook { o.engine.register_fn("now_str", now_str); for r in o.config.receiver.iter() { - let ast = o.engine.compile(&r.script).unwrap(); - if r.enabled { + let ast = o.engine.compile(&r.script).unwrap(); o.ast_list.push(Some(ast)); } else { o.ast_list.push(None); diff --git a/server/src/notifier/wechat.rs b/server/src/notifier/wechat.rs index 02da0349..2ce57008 100644 --- a/server/src/notifier/wechat.rs +++ b/server/src/notifier/wechat.rs @@ -75,10 +75,8 @@ impl crate::notifier::Notifier for WeChat { if let Ok(json_data) = json_res { if let Some(access_token) = json_data.get("access_token") { if let Some(token) = access_token.as_str() { - let req_url = format!( - "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={}", - token - ); + let req_url = + format!("https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={token}"); let req_data = serde_json::json!({ "touser": "@all", "agentid": agent_id, diff --git a/server/src/stats.rs b/server/src/stats.rs index ba1eb861..89dec6ef 100644 --- a/server/src/stats.rs +++ b/server/src/stats.rs @@ -177,7 +177,7 @@ impl StatsMgr { // uptime str let day = (stat_t.uptime as f64 / 3600.0 / 24.0) as i64; if day > 0 { - stat_t.uptime_str = format!("{} 天", day); + stat_t.uptime_str = format!("{day} 天"); } else { stat_t.uptime_str = format!( "{:02}:{:02}:{:02}", @@ -256,7 +256,7 @@ impl StatsMgr { let os_r = sys_info.os_release.to_lowercase(); for s in OS_LIST.iter() { if os_r.contains(s) { - write!(o.labels, ";os={}", s); + write!(o.labels, ";os={s}"); break; } } diff --git a/web/jinja/client-init.jinja.sh b/web/jinja/client-init.jinja.sh index ea5000c5..d8efc92d 100644 --- a/web/jinja/client-init.jinja.sh +++ b/web/jinja/client-init.jinja.sh @@ -110,7 +110,7 @@ function download_client() { cd ${SSR_WORKSPACE} rm -rf client-*.zip stat_* | true - say "start downloading the stat_client" + say "start download the stat_client" if [ "${SSR_CN}" = true ]; then say "using cn mirror: coding.net"