mirror of
https://github.com/sadoyan/aralez.git
synced 2026-10-23 14:11:35 +08:00
fix linter warnings
This commit is contained in:
+22
-1
@@ -9,7 +9,28 @@ use std::time::Duration;
|
||||
|
||||
pub static HC_CONNECTOR: LazyLock<Connector> = LazyLock::new(|| Connector::new(None));
|
||||
|
||||
pub async fn httpclient(method: &str, tls: bool, host: &str, path: &str, address: &str, port: u16, url: &str, payload: Bytes) -> (bool, bool) {
|
||||
pub struct HttpClientRequest<'a> {
|
||||
pub method: &'a str,
|
||||
pub tls: bool,
|
||||
pub host: &'a str,
|
||||
pub path: &'a str,
|
||||
pub address: &'a str,
|
||||
pub port: u16,
|
||||
pub url: &'a str,
|
||||
pub payload: Bytes,
|
||||
}
|
||||
|
||||
pub async fn httpclient(req: HttpClientRequest<'_>) -> (bool, bool) {
|
||||
let HttpClientRequest {
|
||||
method,
|
||||
tls,
|
||||
host,
|
||||
path,
|
||||
address,
|
||||
port,
|
||||
url,
|
||||
payload,
|
||||
} = req;
|
||||
let method = match method {
|
||||
"HEAD" => "HEAD",
|
||||
"GET" => "GET",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::utils::hcclient::httpclient;
|
||||
use crate::utils::hcclient::{httpclient, HttpClientRequest};
|
||||
use crate::utils::lazylock::REVERSE_STORE;
|
||||
use crate::utils::tools::*;
|
||||
use crate::utils::types::{InnerMap, UpstreamsDashMap, UpstreamsIdMap};
|
||||
@@ -68,7 +68,17 @@ async fn build_upstreams(fullist: &UpstreamsDashMap, method: &str) -> UpstreamsD
|
||||
} else {
|
||||
format!("http://{}:{}{}", upstream.address, upstream.port, path)
|
||||
};
|
||||
let resp = httpclient(method, tls, host, path, upstream.address.as_ref(), upstream.port, link.as_str(), EMPTY_PAYLOAD).await;
|
||||
let resp = httpclient(HttpClientRequest {
|
||||
method,
|
||||
tls,
|
||||
host,
|
||||
path,
|
||||
address: upstream.address.as_ref(),
|
||||
port: upstream.port,
|
||||
url: link.as_str(),
|
||||
payload: EMPTY_PAYLOAD,
|
||||
})
|
||||
.await;
|
||||
if resp.0 {
|
||||
if resp.1 {
|
||||
scheme.is_http2 = resp.1;
|
||||
|
||||
@@ -154,7 +154,7 @@ pub async fn for_kuber(url: &str, token: &str, conf: &GlobalServiceMapping) -> O
|
||||
}
|
||||
|
||||
pub async fn getfromapi(url: &str, token: Option<String>, provider: &str) -> Option<Vec<u8>> {
|
||||
let (host, port, path, is_tls) = parse_url(&url).ok()?;
|
||||
let (host, port, path, is_tls) = parse_url(url).ok()?;
|
||||
|
||||
let mut peer = HttpPeer::new((host, port), is_tls, host.to_string());
|
||||
peer.options.total_connection_timeout = Some(Duration::from_secs(5));
|
||||
|
||||
@@ -158,6 +158,13 @@ pub struct InnerMap {
|
||||
pub authorization: Option<Arc<InnerAuth>>,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl Default for InnerMap {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl InnerMap {
|
||||
pub fn new() -> Self {
|
||||
|
||||
+10
-14
@@ -38,13 +38,11 @@ pub async fn file_watch(fp: String, toreturn: Sender<Configuration>) {
|
||||
while let Some(event) = local_rx.recv().await {
|
||||
match event {
|
||||
Ok(e) => match e.kind {
|
||||
EventKind::Modify(ModifyKind::Data(_)) | EventKind::Create(..) | EventKind::Remove(..) => {
|
||||
if start.elapsed() > Duration::from_secs(2) {
|
||||
start = Instant::now();
|
||||
let snd = load_configuration(file_path, "filepath").await.0;
|
||||
if let Some(snd) = snd {
|
||||
toreturn.send(snd).await.unwrap();
|
||||
}
|
||||
EventKind::Modify(ModifyKind::Data(_)) | EventKind::Create(..) | EventKind::Remove(..) if start.elapsed() > Duration::from_secs(2) => {
|
||||
start = Instant::now();
|
||||
let snd = load_configuration(file_path, "filepath").await.0;
|
||||
if let Some(snd) = snd {
|
||||
toreturn.send(snd).await.unwrap();
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
@@ -64,13 +62,11 @@ pub fn folder_watch(path: String, sender: std::sync::mpsc::Sender<Vec<Certificat
|
||||
loop {
|
||||
match rx.recv_timeout(Duration::from_secs(1)) {
|
||||
Ok(Ok(event)) => match &event.kind {
|
||||
EventKind::Modify(ModifyKind::Data(_)) | EventKind::Create(_) | EventKind::Remove(_) => {
|
||||
if start.elapsed() > Duration::from_secs(1) {
|
||||
start = Instant::now();
|
||||
let certificate_configs = listdir(path.clone());
|
||||
sender.send(certificate_configs)?;
|
||||
info!("Certificate changed: {:?}, {:?}", event.kind, event.paths);
|
||||
}
|
||||
EventKind::Modify(ModifyKind::Data(_)) | EventKind::Create(_) | EventKind::Remove(_) if start.elapsed() > Duration::from_secs(1) => {
|
||||
start = Instant::now();
|
||||
let certificate_configs = listdir(path.clone());
|
||||
sender.send(certificate_configs)?;
|
||||
info!("Certificate changed: {:?}, {:?}", event.kind, event.paths);
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user