Skip to content

Commit 3664aec

Browse files
committed
Linted files
1 parent c214399 commit 3664aec

File tree

5 files changed

+13
-49
lines changed

5 files changed

+13
-49
lines changed

src/db.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@ impl DB {
1313
}
1414
}
1515
pub fn get(&self, id: &str) -> Option<String> {
16-
self.conn.query_row("SELECT data FROM pad WHERE id = ?1", &[&id], |row| {
16+
self.conn.query_row("SELECT data FROM pad WHERE id = ?1", [&id], |row| {
1717
row.get(0)
1818
}).ok()
1919
}
2020

2121
pub fn set(&self, id: &str, data: &str) {
22-
self.conn.execute("INSERT OR REPLACE INTO pad (id, data) VALUES (?1, ?2)", &[&id, &data]).unwrap();
22+
self.conn.execute("INSERT OR REPLACE INTO pad (id, data) VALUES (?1, ?2)", [&id, &data]).unwrap();
2323
}
2424

25+
#[allow(unused)]
2526
pub fn delete(&self, id: &str) {
26-
self.conn.execute("DELETE FROM pad WHERE id = ?1", &[&id]).unwrap();
27+
self.conn.execute("DELETE FROM pad WHERE id = ?1", [&id]).unwrap();
2728
}
2829
}

src/main.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,10 @@ use crate::reverse_proxy::{handler, StateOfReverseProxy};
44
use crate::runtime::get_router_config;
55
use crate::settings::Setting;
66
use axum::body::Body;
7-
use axum::extract::Request;
8-
use axum::http::Response;
9-
use axum::routing::any_service;
107
use axum::Router;
118
use hyper_util::client::legacy::connect::HttpConnector;
129
use hyper_util::rt::TokioExecutor;
13-
use std::convert::Infallible;
1410
use std::sync::{Arc, Mutex};
15-
use axum::handler::Handler;
16-
use tower::service_fn;
1711

1812
mod settings;
1913
mod runtime;

src/reverse_proxy.rs

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
1-
use std::collections::HashMap;
21
use crate::db::DB;
32
use crate::runtime::AvailableBackends;
43
use crate::settings::{BackendIdentifier, Setting};
54
use rand::seq::SliceRandom;
6-
use std::convert::Infallible;
7-
use std::fmt::format;
8-
use std::net::IpAddr;
9-
use std::ops::Index;
10-
use std::sync::{Arc, LazyLock, Mutex};
11-
use axum::body::Body;
5+
use std::sync::{Arc, Mutex};
126
use axum::extract::{Request, State};
137
use axum::http::{StatusCode, Uri};
148
use axum::response::{IntoResponse, Response};
159
use crate::Client;
16-
use regex::Regex;
17-
18-
fn debug_request(req: Request<Body>) -> Result<Response<Body>, Infallible> {
19-
let body_str = format!("{:?}", req);
20-
Ok(Response::new(Body::from(body_str)))
21-
}
2210

2311
fn create_route(
2412
pad_id: Option<String>,
@@ -41,7 +29,7 @@ fn create_route(
4129
};
4230
match result {
4331
Some(backend_id) => {
44-
let mut available_backends = available_backends.lock().unwrap();
32+
let available_backends = available_backends.lock().unwrap();
4533
if available_backends.available.is_empty() {
4634
log::error!("No available backends");
4735
return None;
@@ -50,8 +38,7 @@ fn create_route(
5038
if available_backends
5139
.up
5240
.iter()
53-
.position(|e| e == &backend_id)
54-
.is_some()
41+
.any(|e| e == &backend_id)
5542
{
5643
Some(backend_id)
5744
} else {
@@ -78,7 +65,7 @@ fn create_route(
7865
.choose(&mut rand::thread_rng())
7966
.unwrap();
8067
{
81-
let mut locked_db = db.lock().unwrap();
68+
let locked_db = db.lock().unwrap();
8269
locked_db.set(&format!("padId:{}", pad_id), new_backend);
8370
}
8471
log::info!("Creating new association for pad {} with backend {}", pad_id, new_backend);
@@ -99,10 +86,6 @@ pub struct StateOfReverseProxy {
9986
pub setting: Setting,
10087
}
10188

102-
static RESOURCES: LazyLock<HashMap<String, String>> = LazyLock::new(HashMap::new);
103-
104-
static PADINDEX_REGEX: LazyLock<Regex> = LazyLock::new(||Regex::new("^/padbootstrap-[a-zA-Z0-9]+.min.js$").unwrap());
105-
10689

10790
pub async fn handler(State(client): State<StateOfReverseProxy>, mut req: Request) ->
10891
Result<Response,
@@ -159,14 +142,3 @@ pub fn get_pad_id(uri: &Uri) -> Option<String> {
159142
}
160143
pad_id
161144
}
162-
163-
164-
mod tests {
165-
use crate::reverse_proxy::PADINDEX_REGEX;
166-
167-
#[test]
168-
fn test_pad_index_regex() {
169-
let path = "/padbootstrap-KK7I7qP9I3E.min.js";
170-
assert!(PADINDEX_REGEX.is_match(path));
171-
}
172-
}

src/runtime.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
use std::collections::HashMap;
22
use std::sync::{Arc, Mutex};
33
use std::{thread, time};
4-
use hyper::upgrade::Upgraded;
5-
use crate::reverse_proxy::StateOfReverseProxy;
64
use crate::settings::{Backend, BackendIdentifier, Setting};
7-
use tokio_tungstenite::WebSocketStream;
85

96
#[derive(Default)]
107
pub struct AvailableBackends {
@@ -50,7 +47,7 @@ pub async fn check_availability(backends: &HashMap<BackendIdentifier, Backend>,
5047
available = available.iter().filter(|b| *b != id).cloned().collect();
5148
}
5249
}
53-
Err(e)=>{
50+
Err(_)=>{
5451
available = available.iter().filter(|b| *b != id).cloned().collect();
5552
up = up.iter().filter(|b| *b != id).cloned().collect();
5653
}
@@ -78,7 +75,7 @@ pub fn check_availability_sync(backends: &HashMap<BackendIdentifier, Backend>,
7875
available = available.iter().filter(|b| *b != id).cloned().collect();
7976
}
8077
}
81-
Err(e)=>{
78+
Err(_)=>{
8279
available = available.iter().filter(|b| *b != id).cloned().collect();
8380
up = up.iter().filter(|b| *b != id).cloned().collect();
8481
}

src/settings.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ pub struct Backend {
2323
pub port: u16,
2424
}
2525

26-
impl Into<String> for Backend {
27-
fn into(self) -> String {
28-
format!("http://{}:{}/stats", self.host, self.port)
26+
impl From<Backend> for String {
27+
fn from(val: Backend) -> Self {
28+
format!("http://{}:{}/stats", val.host, val.port)
2929
}
3030
}
3131

0 commit comments

Comments
 (0)