Add boilerplate.
This commit is contained in:
parent
8aed3a1680
commit
d755576a17
@ -201,7 +201,19 @@ fn serve(
|
||||
.or(warp::path!("refs" / ..).and_then(not_implemented))
|
||||
.or(warp::path!("repo" / ..).and_then(not_implemented))
|
||||
.or(warp::path!("stats" / ..).and_then(not_implemented))
|
||||
.or(warp::path!("swarm" / ..).and_then(not_implemented))
|
||||
.or(warp::path!("swarm" / "connect")
|
||||
.and(warp::query::<v0::swarm::ConnectQuery>())
|
||||
.and_then(v0::swarm::connect))
|
||||
.or(warp::path!("swarm" / "peers")
|
||||
.and(warp::query::<v0::swarm::PeersQuery>())
|
||||
.and_then(v0::swarm::peers))
|
||||
.or(warp::path!("swarm" / "addrs").and_then(v0::swarm::addrs))
|
||||
.or(warp::path!("swarm" / "addrs" / "local")
|
||||
.and(warp::query::<v0::swarm::AddrsLocalQuery>())
|
||||
.and_then(v0::swarm::addrs_local))
|
||||
.or(warp::path!("swarm" / "disconnect")
|
||||
.and(warp::query::<v0::swarm::DisconnectQuery>())
|
||||
.and_then(v0::swarm::disconnect))
|
||||
.or(warp::path!("version")
|
||||
.and(warp::query::<v0::version::Query>())
|
||||
.and_then(v0::version::version));
|
||||
|
@ -1,3 +1,3 @@
|
||||
pub mod version;
|
||||
|
||||
// pub mod id;
|
||||
pub mod swarm;
|
||||
|
103
http/src/v0/swarm.rs
Normal file
103
http/src/v0/swarm.rs
Normal file
@ -0,0 +1,103 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ConnectQuery {
|
||||
arg: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
pub struct ConnectResponse {
|
||||
strings: Vec<String>,
|
||||
}
|
||||
|
||||
pub async fn connect(query: ConnectQuery) -> Result<impl warp::Reply, std::convert::Infallible> {
|
||||
let response = ConnectResponse { strings: vec![] };
|
||||
Ok(warp::reply::json(&response))
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct PeersQuery {
|
||||
verbose: Option<bool>,
|
||||
streams: Option<bool>,
|
||||
latency: Option<bool>,
|
||||
direction: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
pub struct PeersResponse {
|
||||
peers: Vec<Peer>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
pub struct Peer {
|
||||
addr: String,
|
||||
direction: u32,
|
||||
latency: String,
|
||||
muxer: String,
|
||||
peer: String,
|
||||
streams: Vec<Stream>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
pub struct Stream {
|
||||
protocol: String,
|
||||
}
|
||||
|
||||
pub async fn peers(query: PeersQuery) -> Result<impl warp::Reply, std::convert::Infallible> {
|
||||
let response = PeersResponse { peers: vec![] };
|
||||
Ok(warp::reply::json(&response))
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
pub struct AddrsResponse {
|
||||
addrs: BTreeMap<String, Vec<String>>,
|
||||
}
|
||||
|
||||
pub async fn addrs() -> Result<impl warp::Reply, std::convert::Infallible> {
|
||||
let response = AddrsResponse {
|
||||
addrs: BTreeMap::new(),
|
||||
};
|
||||
Ok(warp::reply::json(&response))
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct AddrsLocalQuery {
|
||||
id: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
pub struct AddrsLocalResponse {
|
||||
strings: Vec<String>,
|
||||
}
|
||||
|
||||
pub async fn addrs_local(
|
||||
query: AddrsLocalQuery,
|
||||
) -> Result<impl warp::Reply, std::convert::Infallible> {
|
||||
let response = AddrsLocalResponse { strings: vec![] };
|
||||
Ok(warp::reply::json(&response))
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct DisconnectQuery {
|
||||
arg: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
pub struct DisconnectResponse {
|
||||
strings: Vec<String>,
|
||||
}
|
||||
|
||||
pub async fn disconnect(
|
||||
query: DisconnectQuery,
|
||||
) -> Result<impl warp::Reply, std::convert::Infallible> {
|
||||
let response = DisconnectResponse { strings: vec![] };
|
||||
Ok(warp::reply::json(&response))
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user