Skip to content

Commit cb37dd5

Browse files
committed
style: cargo fmt
1 parent b96df03 commit cb37dd5

34 files changed

+198
-178
lines changed

src/config/_redis.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
use redis::{Client, aio::MultiplexedConnection};
2-
use std::sync::Arc;
1+
use redis::{aio::MultiplexedConnection, Client};
32
use std::env;
3+
use std::sync::Arc;
44

5-
pub async fn connect() -> Result<Arc<MultiplexedConnection>, Box<dyn std::error::Error + Send + Sync>> {
6-
let redis_url = env::var("REDIS_URL")
7-
.unwrap_or_else(|_| "redis://localhost:6379".to_string());
5+
pub async fn connect(
6+
) -> Result<Arc<MultiplexedConnection>, Box<dyn std::error::Error + Send + Sync>> {
7+
let redis_url = env::var("REDIS_URL").unwrap_or_else(|_| "redis://localhost:6379".to_string());
88

99
let client = Client::open(redis_url)?;
10-
10+
1111
// 获取异步 MultiplexedConnection
1212
let conn = client.get_multiplexed_async_connection().await?;
13-
13+
1414
log::info!("Connected to Redis successfully!");
15-
15+
1616
Ok(Arc::new(conn))
1717
}
1818

@@ -32,4 +32,4 @@ pub fn get_redis_queue_database() -> i64 {
3232
.unwrap_or_else(|_| "1".to_string())
3333
.parse()
3434
.unwrap_or(1)
35-
}
35+
}

src/config/database.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
use mongodb::{Client, options::ClientOptions};
1+
use mongodb::{options::ClientOptions, Client};
22
use std::env;
33

44
pub async fn connect() -> Result<Client, Box<dyn std::error::Error>> {
5-
let uri = env::var("MONGODB_URI")
6-
.unwrap_or_else(|_| "mongodb://localhost:27017".to_string());
7-
5+
let uri = env::var("MONGODB_URI").unwrap_or_else(|_| "mongodb://localhost:27017".to_string());
6+
87
let client_options = ClientOptions::parse(&uri).await?;
98
let client = Client::with_options(client_options)?;
10-
9+
1110
// 测试连接
1211
client
1312
.database("admin")
1413
.run_command(mongodb::bson::doc! {"ping": 1}, None)
1514
.await?;
16-
15+
1716
log::info!("Connected to MongoDB successfully!");
1817
Ok(client)
1918
}
2019

2120
pub fn get_database_name() -> String {
2221
env::var("DATABASE_NAME").unwrap_or_else(|_| "mcim_backend".to_string())
23-
}
22+
}

src/config/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
pub mod database;
21
pub mod _redis;
2+
pub mod database;
33

4-
use std::sync::Arc;
54
use redis::aio::MultiplexedConnection;
5+
use std::sync::Arc;
66

77
#[derive(Clone)]
88
pub struct AppState {
@@ -13,4 +13,4 @@ pub struct AppState {
1313
pub curseforge_api_key: String,
1414
pub curseforge_file_cdn_url: String,
1515
pub modrinth_file_cdn_url: String,
16-
}
16+
}

src/errors/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
pub mod services;
21
pub mod routes;
2+
pub mod services;
33

4-
pub use services::ServiceError;
4+
pub use routes::map_actix_error;
55
pub use routes::ApiError;
6-
pub use routes::map_actix_error;
6+
pub use services::ServiceError;

src/errors/services.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use mongodb::error::Error as MongoError;
12
use std::error::Error as StdError;
23
use std::fmt::{Display, Formatter};
3-
use mongodb::error::Error as MongoError;
44

55
#[derive(Debug)]
66
pub enum ServiceError {
@@ -77,4 +77,3 @@ impl From<serde_json::Error> for ServiceError {
7777
ServiceError::UnexpectedError(format!("JSON serialization error: {}", err))
7878
}
7979
}
80-

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ pub mod routes;
55
pub mod services;
66
pub mod utils;
77

8+
use actix_middleware_etag::Etag;
89
use actix_web::middleware::{Compress, Logger};
910
use actix_web::{dev::ServiceRequest, web, App, HttpServer};
10-
use actix_middleware_etag::{Etag};
1111
use dotenvy::dotenv;
1212
use std::env;
1313

src/models/common/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// pub mod entities;
22
pub mod requests;
3-
pub mod responses;
3+
pub mod responses;

src/models/common/requests.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use serde::Deserialize;
22

3-
43
#[derive(Deserialize)]
54
pub struct StatisticsQuery {
65
pub curseforge: Option<bool>,
76
pub modrinth: Option<bool>,
87
pub translate: Option<bool>,
9-
}
8+
}

src/models/common/responses.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use serde::Serialize;
2-
use utoipa::{ToSchema};
2+
use utoipa::ToSchema;
33

44
#[derive(Serialize, ToSchema)]
55
pub struct StatisticsResponse {
66
pub curseforge: Option<i64>,
77
pub modrinth: Option<i64>,
88
pub translate: Option<i64>,
9-
}
9+
}

src/models/curseforge/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
pub mod entities;
22
pub mod requests;
3-
pub mod responses;
3+
pub mod responses;

0 commit comments

Comments
 (0)