Skip to content

Commit 65be735

Browse files
authored
Update dependencies and refactor start function (#24)
* Update dependencies and refactor start function Signed-off-by: yaokunzhang <[email protected]> * Improve file handling and fix clippy warnings - Remove ineffective `.write(true)` from OpenOptions to address clippy warning regarding ineffective open options. - Enhance error handling in file line reading by replacing `.flatten()` with `.filter_map(Result::ok)`, ensuring any read errors are properly managed. Signed-off-by: yaokunzhang <[email protected]> --------- Signed-off-by: yaokunzhang <[email protected]>
1 parent 6a9dc9d commit 65be735

File tree

4 files changed

+18
-28
lines changed

4 files changed

+18
-28
lines changed

Cargo.toml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ name = "api"
1212
path = "src/api.rs"
1313

1414
[dependencies]
15-
regex = "1.5.4"
16-
clap = { version = "4.2.4", features = ["derive"] }
17-
toml = "0.8.0"
18-
walkdir = "2.3.2"
19-
rayon = "1.5.1"
15+
regex = "1.10.3"
16+
clap = { version = "4.5.3", features = ["derive"] }
17+
toml = "0.8.12"
18+
walkdir = "2.5.0"
19+
rayon = "1.9.1"
2020
serde = { version = "1.0", features = ["derive"] }
2121
serde_json = "1.0"
2222
chrono = "0.4"
@@ -27,9 +27,9 @@ mockito = "1.0.2"
2727
csv = "1.1"
2828
log = "0.4"
2929
env_logger = "0.11.0"
30-
axum = { version = "0.6.1", features = ["headers", "macros"] }
31-
tokio = { version = "1.21.2", features = ["macros", "rt-multi-thread"] }
30+
axum = { version = "0.7.4", features = ["macros"] }
31+
tokio = { version = "1.36.0", features = ["macros", "rt-multi-thread"] }
3232
tower-http = { version = "0.5.0", features = ["cors"] }
33-
utoipa = { version = "3.3.0", features = ["axum_extras"] }
34-
utoipa-swagger-ui = { version = "3.1.3", features = ["axum"] }
35-
hyper = { version = "0.14", features = ["full"] }
33+
utoipa = { version = "4.2.0", features = ["axum_extras"] }
34+
utoipa-swagger-ui = { version = "6", features = ["axum"] }
35+
hyper = { version = "1.2.0", features = ["full"] }

src/lib.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub mod service{
1313
pub mod git_service;
1414
}
1515

16-
pub use entity::models;
16+
pub use entity::models;
1717

1818

1919
pub use errors::*;
@@ -25,16 +25,7 @@ pub use utils::git_util;
2525
pub use git_util::*;
2626
pub use models::*;
2727

28-
29-
30-
31-
use std::{
32-
net::{Ipv4Addr, SocketAddr},
33-
34-
};
35-
36-
use axum::{routing, Router, Server};
37-
use hyper::Error;
28+
use axum::{routing, Router};
3829
use utoipa::{
3930
OpenApi,
4031
};
@@ -53,7 +44,7 @@ pub use routes::rules::*;
5344

5445

5546

56-
pub async fn start() -> Result<(), Error> {
47+
pub async fn start() -> Result<(), Box<dyn std::error::Error>> {
5748
#[derive(OpenApi)]
5849
#[openapi(
5950
paths(
@@ -84,9 +75,9 @@ pub async fn start() -> Result<(), Error> {
8475
.route("/rules/delete_rules_by_id", routing::post(delete_rules_by_id))
8576
.route("/rules/update", routing::post(update_rules));
8677

87-
88-
let address = SocketAddr::from((Ipv4Addr::UNSPECIFIED, 7000));
89-
Server::bind(&address).serve(app.into_make_service()).await
78+
let listener = tokio::net::TcpListener::bind("0.0.0.0:7000").await.unwrap();
79+
axum::serve(listener, app.into_make_service()).await?;
80+
Ok(())
9081
}
9182

9283

src/service/git_service.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ pub fn handle_commits_file(
109109

110110
let mut commits: Vec<String> = Vec::new();
111111

112-
// Read each line from the file and store it in the commits vector
113-
for line in reader.lines().flatten() {
112+
// Read each line from the file, stopping at the first error
113+
for line in reader.lines().map_while(Result::ok) {
114114
commits.push(line);
115115
}
116116

src/utils/detect_utils.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@ pub fn append_rule_to_toml(rule: &Rule, filename: &str) -> Result<(), Box<dyn st
378378
// Open the file with read, write, and append options
379379
let mut file = OpenOptions::new()
380380
.read(true)
381-
.write(true)
382381
.append(true)
383382
.open(filename)?;
384383

0 commit comments

Comments
 (0)