Some decentralize

This commit is contained in:
2024-03-22 14:09:27 +05:00
parent 54c82537b7
commit a6ab0d0945
5 changed files with 187 additions and 91 deletions

42
src/api/v0.rs Normal file
View File

@ -0,0 +1,42 @@
use {
hyper::{
Request,
body::{
Incoming,
},
},
serde_json::{
Value as Json,
json,
},
skytable::pool::ConnectionMgrTcp,
bb8::Pool,
std::sync::Arc,
crate::double_split,
};
type Res<T, E> = std::result::Result<T, E>;
type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
type DBPool = Arc<Pool<ConnectionMgrTcp>>;
pub async fn api(req: Request<Incoming>, pool: DBPool) -> Json {
let uri: &str = req.uri().path().as_ref();
match &uri[7..uri.len()] {
"/test" => json!({"error": false, "msg": "test endpoint v0"}),
"/auth" => auth(req, pool.clone()).await,
"/auth_get" => auth_get(req, pool.clone()).await,
_ => json!({"error": true, "msg": "No endpoint"})
}
}
async fn auth(req: Request<Incoming>, pool: DBPool) -> Json {
json!({"error": false, "msg": "test auth endpoint v0"})
}
async fn auth_get(req: Request<Incoming>, pool: DBPool) -> Json {
let query = req.uri().query().or(Some("")).unwrap();
let query = double_split(query.to_string(), "&", "=");
println!("{:?}", query);
json!({"error": false, "msg": "test auth_get endpoint v0"})
}