From 6612e020ff86f7db5fb49554b2137c17d09bf726 Mon Sep 17 00:00:00 2001 From: Daan Boerlage Date: Thu, 6 Apr 2023 18:31:40 +0200 Subject: [PATCH] cargo fmt --- src/api/endpoints/mod.rs | 7 ++----- src/api/endpoints/stats.rs | 8 ++++---- src/api/endpoints/worlds.rs | 8 ++++---- src/api/mod.rs | 2 +- src/collectors/mod.rs | 6 ++++-- src/collectors/player_count.rs | 10 +++++----- src/collectors/stats.rs | 29 ++++++++++------------------- src/lifecycle/mod.rs | 2 +- src/lifecycle/shutdown.rs | 4 ++-- src/main.rs | 8 ++++---- src/transport/http.rs | 16 +++++++++++----- src/transport/mod.rs | 2 +- 12 files changed, 49 insertions(+), 53 deletions(-) diff --git a/src/api/endpoints/mod.rs b/src/api/endpoints/mod.rs index 46a3ca9..39326a6 100644 --- a/src/api/endpoints/mod.rs +++ b/src/api/endpoints/mod.rs @@ -3,10 +3,7 @@ pub mod worlds; use crate::collectors::PromMetric; fn convert_into_prom_metrics(data: Vec) -> String { - let metrics: Vec = data - .into_iter() - .map(|w| w.to_metric_string()) - .collect(); + let metrics: Vec = data.into_iter().map(|w| w.to_metric_string()).collect(); metrics.join("\n") -} \ No newline at end of file +} diff --git a/src/api/endpoints/stats.rs b/src/api/endpoints/stats.rs index 6b46ca6..054d72a 100644 --- a/src/api/endpoints/stats.rs +++ b/src/api/endpoints/stats.rs @@ -1,14 +1,14 @@ +use super::convert_into_prom_metrics; +use crate::collectors::stats::get_player_stats; use axum::extract::Path; use axum::http::StatusCode; use axum::response::IntoResponse; -use crate::collectors::stats::get_player_stats; -use super::convert_into_prom_metrics; pub async fn get_stats(Path(rsn): Path) -> impl IntoResponse { let resp = match get_player_stats(&rsn).await { Ok(r) => r, - Err(_) => return (StatusCode::INTERNAL_SERVER_ERROR, "Nope".to_string()) + Err(_) => return (StatusCode::INTERNAL_SERVER_ERROR, "Nope".to_string()), }; (StatusCode::OK, convert_into_prom_metrics(resp)) -} \ No newline at end of file +} diff --git a/src/api/endpoints/worlds.rs b/src/api/endpoints/worlds.rs index 665a17e..9b2d131 100644 --- a/src/api/endpoints/worlds.rs +++ b/src/api/endpoints/worlds.rs @@ -1,13 +1,13 @@ +use super::convert_into_prom_metrics; +use crate::collectors::player_count::get_player_count; use axum::http::StatusCode; use axum::response::IntoResponse; -use crate::collectors::player_count::get_player_count; -use super::convert_into_prom_metrics; pub async fn get_worlds() -> impl IntoResponse { let resp = match get_player_count().await { Ok(r) => r, - Err(_) => return (StatusCode::INTERNAL_SERVER_ERROR, "Nope".to_string()) + Err(_) => return (StatusCode::INTERNAL_SERVER_ERROR, "Nope".to_string()), }; (StatusCode::OK, convert_into_prom_metrics(resp)) -} \ No newline at end of file +} diff --git a/src/api/mod.rs b/src/api/mod.rs index e0d74d3..c4b360f 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -1 +1 @@ -pub mod endpoints; \ No newline at end of file +pub mod endpoints; diff --git a/src/collectors/mod.rs b/src/collectors/mod.rs index 39a7287..b52f733 100644 --- a/src/collectors/mod.rs +++ b/src/collectors/mod.rs @@ -23,6 +23,8 @@ async fn get_runelite_version() -> eyre::Result { if let Some(latest) = resp.first() { Ok(latest.name.replace("parent-", "")) } else { - Err(eyre::eyre!("Failed to get github tags for runelite version")) + Err(eyre::eyre!( + "Failed to get github tags for runelite version" + )) } -} \ No newline at end of file +} diff --git a/src/collectors/player_count.rs b/src/collectors/player_count.rs index dc8813f..373a5f0 100644 --- a/src/collectors/player_count.rs +++ b/src/collectors/player_count.rs @@ -1,7 +1,7 @@ +use super::PromMetric; use serde::{Deserialize, Deserializer}; use std::fmt::{Display, Formatter}; use std::str; -use super::PromMetric; #[derive(Deserialize, Debug)] pub struct Worlds { @@ -19,8 +19,8 @@ pub enum WorldLocation { impl<'de> Deserialize<'de> for WorldLocation { fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, + where + D: Deserializer<'de>, { let field = i16::deserialize(deserializer)?; let world = match field { @@ -67,8 +67,8 @@ pub enum WorldType { impl<'de> Deserialize<'de> for WorldType { fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, + where + D: Deserializer<'de>, { let field = String::deserialize(deserializer)?; let res = match field.as_str() { diff --git a/src/collectors/stats.rs b/src/collectors/stats.rs index 7d882f4..9be9744 100644 --- a/src/collectors/stats.rs +++ b/src/collectors/stats.rs @@ -1,5 +1,5 @@ -use std::fmt::{Display, Formatter}; use eyre::eyre; +use std::fmt::{Display, Formatter}; #[derive(Debug)] pub struct SkillInfo { @@ -67,11 +67,11 @@ const SKILLS: [&str; 25] = [ ]; pub async fn get_player_stats(rsn: &str) -> eyre::Result> { - let req_url = format!("https://oldschool.runescape.wiki/cors/m=hiscore_oldschool/index_lite.ws?player={}", rsn); - let resp = crate::transport::http::new() - .get(req_url) - .send() - .await?; + let req_url = format!( + "https://oldschool.runescape.wiki/cors/m=hiscore_oldschool/index_lite.ws?player={}", + rsn + ); + let resp = crate::transport::http::new().get(req_url).send().await?; if resp.status() != 200 { return Err(eyre!("Player not found")); @@ -106,27 +106,18 @@ impl super::PromMetric for SkillInfo { let lines: Vec = vec![ format!( "osrs_player_rank{{skill=\"{}\",player=\"{}\",profile=\"{}\"}} {}", - self.name, - self.player, - self.profile, - self.rank + self.name, self.player, self.profile, self.rank ), format!( "osrs_player_level{{skill=\"{}\",player=\"{}\",profile=\"{}\"}} {}", - self.name, - self.player, - self.profile, - self.level + self.name, self.player, self.profile, self.level ), format!( "osrs_player_xp{{skill=\"{}\",player=\"{}\",profile=\"{}\"}} {}", - self.name, - self.player, - self.profile, - self.xp + self.name, self.player, self.profile, self.xp ), ]; lines.join("\n") } -} \ No newline at end of file +} diff --git a/src/lifecycle/mod.rs b/src/lifecycle/mod.rs index 6567761..de8498c 100644 --- a/src/lifecycle/mod.rs +++ b/src/lifecycle/mod.rs @@ -1 +1 @@ -pub mod shutdown; \ No newline at end of file +pub mod shutdown; diff --git a/src/lifecycle/shutdown.rs b/src/lifecycle/shutdown.rs index edee062..dff2346 100644 --- a/src/lifecycle/shutdown.rs +++ b/src/lifecycle/shutdown.rs @@ -6,7 +6,7 @@ pub async fn shutdown_signal() { }; #[cfg(unix)] - let terminate = async { + let terminate = async { tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate()) .expect("failed to install signal handler") .recv() @@ -14,7 +14,7 @@ pub async fn shutdown_signal() { }; #[cfg(not(unix))] - let terminate = std::future::pending::<()>(); + let terminate = std::future::pending::<()>(); tokio::select! { _ = ctrl_c => {}, diff --git a/src/main.rs b/src/main.rs index e3ffaaa..0a7a772 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,12 +3,12 @@ mod collectors; mod lifecycle; mod transport; -use axum::{Router, BoxError}; -use axum::routing::get; -use axum_tracing_opentelemetry::{response_with_trace_layer, opentelemetry_tracing_layer}; -use std::net::SocketAddr; use api::endpoints::stats; use api::endpoints::worlds; +use axum::routing::get; +use axum::{BoxError, Router}; +use axum_tracing_opentelemetry::{opentelemetry_tracing_layer, response_with_trace_layer}; +use std::net::SocketAddr; #[tokio::main] async fn main() -> Result<(), BoxError> { diff --git a/src/transport/http.rs b/src/transport/http.rs index 7a9a6eb..fe17a16 100644 --- a/src/transport/http.rs +++ b/src/transport/http.rs @@ -1,9 +1,9 @@ +use async_trait::async_trait; use reqwest::{Request, Response}; use reqwest_middleware::{ClientBuilder, ClientWithMiddleware}; use reqwest_middleware::{Middleware, Next, Result}; -use reqwest_retry::{RetryTransientMiddleware, policies::ExponentialBackoff}; +use reqwest_retry::{policies::ExponentialBackoff, RetryTransientMiddleware}; use reqwest_tracing::TracingMiddleware; -use async_trait::async_trait; pub const USER_AGENT: &str = "osrs-prometheus-exporter"; @@ -24,14 +24,20 @@ struct DefaultHeaderMiddleware {} impl DefaultHeaderMiddleware { fn new() -> Self { - DefaultHeaderMiddleware{} + DefaultHeaderMiddleware {} } } #[async_trait] impl Middleware for DefaultHeaderMiddleware { - async fn handle(&self, mut req: Request, extensions: &mut task_local_extensions::Extensions, next: Next<'_>) -> Result { - req.headers_mut().insert("User-Agent", USER_AGENT.parse().unwrap()); + async fn handle( + &self, + mut req: Request, + extensions: &mut task_local_extensions::Extensions, + next: Next<'_>, + ) -> Result { + req.headers_mut() + .insert("User-Agent", USER_AGENT.parse().unwrap()); next.run(req, extensions).await } } diff --git a/src/transport/mod.rs b/src/transport/mod.rs index e05256f..3883215 100644 --- a/src/transport/mod.rs +++ b/src/transport/mod.rs @@ -1 +1 @@ -pub mod http; \ No newline at end of file +pub mod http;