mirror of
https://github.com/sadoyan/aralez.git
synced 2026-04-29 22:38:36 +08:00
Cleanup
This commit is contained in:
@@ -1,18 +1,19 @@
|
||||
use dashmap::DashMap;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use tokio::sync::{RwLockReadGuard, RwLockWriteGuard};
|
||||
use tokio::sync::RwLockReadGuard;
|
||||
|
||||
/*
|
||||
#[allow(dead_code)]
|
||||
pub fn dashmaps(map1: &RwLockWriteGuard<DashMap<String, (Vec<(String, u16)>, AtomicUsize)>>, map2: &DashMap<String, (Vec<(String, u16)>, AtomicUsize)>) -> bool {
|
||||
if map1.len() != map2.len() {
|
||||
return false; // Different number of keys
|
||||
return false;
|
||||
}
|
||||
for entry1 in map1.iter() {
|
||||
let key = entry1.key();
|
||||
let (vec1, _) = entry1.value(); // Extract value
|
||||
let (vec1, _) = entry1.value();
|
||||
|
||||
if let Some(entry2) = map2.get(key) {
|
||||
let (vec2, _) = entry2.value(); // Correctly extract value
|
||||
let (vec2, _) = entry2.value();
|
||||
if vec1 != vec2 {
|
||||
return false;
|
||||
}
|
||||
@@ -22,6 +23,7 @@ pub fn dashmaps(map1: &RwLockWriteGuard<DashMap<String, (Vec<(String, u16)>, Ato
|
||||
}
|
||||
true
|
||||
}
|
||||
*/
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn dm(map1: &RwLockReadGuard<DashMap<String, (Vec<(String, u16)>, AtomicUsize)>>, map2: &DashMap<String, (Vec<(String, u16)>, AtomicUsize)>) -> bool {
|
||||
|
||||
@@ -26,9 +26,6 @@ pub trait Discovery {
|
||||
impl Discovery for APIUpstreamProvider {
|
||||
async fn run(&self, toreturn: Sender<DashMap<String, (Vec<(String, u16)>, AtomicUsize)>>) {
|
||||
webserver::run_server(toreturn).await;
|
||||
// let _ = tokio::spawn(async move { webserver::run_server(toreturn).await });
|
||||
// let (_rtx, mut rrx) = tokio::sync::mpsc::channel::<bool>(1);
|
||||
// let _ = rrx.blocking_recv();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,12 +60,8 @@ pub async fn watch_file(fp: String, mut toreturn: Sender<DashMap<String, (Vec<(S
|
||||
)
|
||||
.unwrap();
|
||||
watcher.watch(&parent_dir, RecursiveMode::Recursive).unwrap();
|
||||
// println!("========================");
|
||||
let (_rtx, mut rrx) = tokio::sync::mpsc::channel::<bool>(1);
|
||||
let _ = rrx.blocking_recv();
|
||||
// loop {
|
||||
// std::thread::sleep(Duration::from_secs(50));
|
||||
// }
|
||||
}
|
||||
});
|
||||
let mut start = Instant::now();
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use axum::body::Body;
|
||||
use axum::http::{Response, StatusCode};
|
||||
use axum::routing::post;
|
||||
use axum::{routing::get, Json, Router};
|
||||
use axum::response::IntoResponse;
|
||||
use axum::routing::{delete, get, head, post, put};
|
||||
use axum::{Json, Router};
|
||||
use dashmap::DashMap;
|
||||
use futures::channel::mpsc::Sender;
|
||||
use futures::SinkExt;
|
||||
@@ -19,7 +20,11 @@ struct UpstreamData {
|
||||
pub async fn run_server(mut toreturn: Sender<DashMap<String, (Vec<(String, u16)>, AtomicUsize)>>) {
|
||||
let mut tr = toreturn.clone();
|
||||
let app = Router::new()
|
||||
.route("/", get(getconfig))
|
||||
.route("/{*wildcard}", get(getconfig))
|
||||
.route("/{*wildcard}", post(getconfig))
|
||||
.route("/{*wildcard}", put(getconfig))
|
||||
.route("/{*wildcard}", head(getconfig))
|
||||
.route("/{*wildcard}", delete(getconfig))
|
||||
.route(
|
||||
"/conf",
|
||||
post(|up: String| async move {
|
||||
@@ -45,8 +50,9 @@ pub async fn run_server(mut toreturn: Sender<DashMap<String, (Vec<(String, u16)>
|
||||
axum::serve(listener, app).await.unwrap();
|
||||
}
|
||||
|
||||
async fn getconfig() -> String {
|
||||
"Hello from Axum API inside Pingora!\n".to_string()
|
||||
async fn getconfig() -> impl IntoResponse {
|
||||
"Hello from Axum API inside Pingora!\n".to_string();
|
||||
Response::builder().status(StatusCode::BAD_GATEWAY).body(Body::from("No live upstream found!\n")).unwrap()
|
||||
}
|
||||
// curl -XPOST -H 'Content-Type: application/json' --data-binary @./push.json 127.0.0.1:3000/json
|
||||
// curl -XPOST --data-binary @./etc/upstreams.txt 127.0.0.1:3000/conf
|
||||
|
||||
Reference in New Issue
Block a user