Let channel search consider backend

This commit is contained in:
Dominik Werder
2024-01-25 23:52:04 +01:00
parent b5ce2dd743
commit a0490abe0c
7 changed files with 99 additions and 16 deletions

View File

@@ -132,7 +132,7 @@ async fn go() -> Result<(), Error> {
Shape::from_dims_str(&opts.shape).unwrap(),
)
.await
.map_err(|_| Error::with_msg_no_trace("error"))
.map_err(|e| Error::with_msg_no_trace(format!("got error: {e}")))
.unwrap();
}
},

View File

@@ -2,7 +2,6 @@ use futures_util::future;
use futures_util::StreamExt;
use http::header;
use http::Method;
use http::StatusCode;
use httpclient::body_empty;
use httpclient::connect_client;
use httpclient::http;
@@ -11,34 +10,46 @@ use httpclient::IncomingStream;
use netpod::log::*;
use netpod::ScalarType;
use netpod::Shape;
use netpod::APP_CBOR_FRAMES;
use std::fmt;
use streams::cbor::FramedBytesToSitemtyDynEventsStream;
use url::Url;
pub struct Error {}
pub struct Error {
msg: String,
}
impl fmt::Display for Error {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "{}", self.msg)
}
}
impl<T> From<T> for Error
where
T: fmt::Debug,
{
fn from(_value: T) -> Self {
Self {}
fn from(value: T) -> Self {
Self {
msg: format!("{value:?}"),
}
}
}
pub async fn fetch_cbor(url: &str, scalar_type: ScalarType, shape: Shape) -> Result<(), Error> {
let url: Url = url.parse().unwrap();
let accept = "application/cbor";
let url: Url = url.parse()?;
debug!("parsed url: {url:?}");
let req = Request::builder()
.method(Method::GET)
.uri(url.to_string())
.header(header::HOST, url.host_str().ok_or_else(|| "NoHostname")?)
.header(header::ACCEPT, accept)
.header(header::ACCEPT, APP_CBOR_FRAMES)
.body(body_empty())?;
debug!("open connection to {:?}", req.uri());
let mut send_req = connect_client(req.uri()).await?;
let res = send_req.send_request(req).await?;
let (head, body) = res.into_parts();
debug!("http_get head {head:?}");
debug!("fetch_cbor head {head:?}");
let stream = IncomingStream::new(body);
let stream = FramedBytesToSitemtyDynEventsStream::new(stream, scalar_type, shape);
let stream = stream.map(|item| info!("{item:?}"));