Some decentralize
This commit is contained in:
42
src/api/v0.rs
Normal file
42
src/api/v0.rs
Normal 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"})
|
||||
}
|
Reference in New Issue
Block a user