Some decentralize
This commit is contained in:
36
src/api.rs
Normal file
36
src/api.rs
Normal file
@ -0,0 +1,36 @@
|
||||
mod v0;
|
||||
|
||||
use {
|
||||
hyper::{
|
||||
StatusCode,
|
||||
Request,
|
||||
header::HeaderValue,
|
||||
body::{
|
||||
Incoming,
|
||||
},
|
||||
},
|
||||
serde_json::{
|
||||
Value as Json,
|
||||
json,
|
||||
},
|
||||
skytable::pool::ConnectionMgrTcp,
|
||||
bb8::Pool,
|
||||
std::sync::Arc,
|
||||
};
|
||||
|
||||
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 endpoint(req: Request<Incoming>, pool: DBPool) -> (String, StatusCode, HeaderValue) {
|
||||
let uri: &str = req.uri().path().as_ref();
|
||||
let res: Json = match &uri[4..uri.len()] {
|
||||
"/test" => json!({"error": false, "msg": "test"}),
|
||||
x if x.starts_with("/v0/") => v0::api(req, pool.clone()).await,
|
||||
_ => json!({"error": true, "msg": "No endpoint"})
|
||||
};
|
||||
|
||||
let restype: HeaderValue = "application/json".parse().unwrap();
|
||||
(res.to_string(), StatusCode::IM_A_TEAPOT, restype)
|
||||
}
|
Reference in New Issue
Block a user