Move workspace crates into subfolder
This commit is contained in:
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
members = ["daqbuffer", "httpret", "h5out", "items_proc", "nodenet", "httpclient", "dq"]
|
members = ["crates/*"]
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
opt-level = 1
|
opt-level = 1
|
||||||
|
|||||||
@@ -19,11 +19,11 @@ pub enum ConfigError {
|
|||||||
Error,
|
Error,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ConfigError {
|
// impl fmt::Display for ConfigError {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
// fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(fmt, "ConfigError::{self:?}")
|
// write!(fmt, "ConfigError::{self:?}")
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
impl From<ConfigParseError> for ConfigError {
|
impl From<ConfigParseError> for ConfigError {
|
||||||
fn from(value: ConfigParseError) -> Self {
|
fn from(value: ConfigParseError) -> Self {
|
||||||
@@ -17,6 +17,8 @@ pub mod read3;
|
|||||||
pub mod read4;
|
pub mod read4;
|
||||||
pub mod streamlog;
|
pub mod streamlog;
|
||||||
|
|
||||||
|
pub use parse;
|
||||||
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use bytes::BytesMut;
|
use bytes::BytesMut;
|
||||||
use err::Error;
|
use err::Error;
|
||||||
@@ -4,6 +4,9 @@ version = "0.0.3"
|
|||||||
authors = ["Dominik Werder <dominik.werder@gmail.com>"]
|
authors = ["Dominik Werder <dominik.werder@gmail.com>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
doctest = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
backtrace = "0.3"
|
backtrace = "0.3"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
@@ -16,5 +19,6 @@ chrono = { version = "0.4", features = ["serde"] }
|
|||||||
url = "2.2"
|
url = "2.2"
|
||||||
regex = "1.5"
|
regex = "1.5"
|
||||||
http = "0.2"
|
http = "0.2"
|
||||||
thiserror = "1.0"
|
#thiserror = "1.0"
|
||||||
|
thiserror = { path = "../../../thiserror" }
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
pub use anyhow;
|
pub use anyhow;
|
||||||
pub use thiserror;
|
pub use thiserror;
|
||||||
|
pub use thiserror::Error as ThisError;
|
||||||
|
|
||||||
pub mod bt {
|
pub mod bt {
|
||||||
pub use backtrace::Backtrace;
|
pub use backtrace::Backtrace;
|
||||||
@@ -20,13 +21,13 @@ use std::sync::PoisonError;
|
|||||||
|
|
||||||
pub type Res2<T> = anyhow::Result<T>;
|
pub type Res2<T> = anyhow::Result<T>;
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, ThisError)]
|
||||||
pub enum ErrA {
|
pub enum ErrA {
|
||||||
#[error("bad-A")]
|
#[error("bad-A")]
|
||||||
Bad,
|
Bad,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, ThisError)]
|
||||||
pub enum ErrB {
|
pub enum ErrB {
|
||||||
#[error("worse-B")]
|
#[error("worse-B")]
|
||||||
Worse,
|
Worse,
|
||||||
@@ -474,3 +475,48 @@ pub fn todoval<T>() -> T {
|
|||||||
eprintln!("TODO\n{bt:?}");
|
eprintln!("TODO\n{bt:?}");
|
||||||
todo!("TODO todoval\n{bt:?}")
|
todo!("TODO todoval\n{bt:?}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait ToPublicError: std::error::Error {
|
||||||
|
fn to_public_error(&self) -> String;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[derive(Debug, ThisError, Serialize, Deserialize)]
|
||||||
|
enum SomeErrorEnumA {
|
||||||
|
BadCase,
|
||||||
|
WithStringContent(String),
|
||||||
|
#[error("bad: {0}")]
|
||||||
|
WithStringContentFmt(String),
|
||||||
|
}
|
||||||
|
|
||||||
|
fn failing_a() -> Result<(), SomeErrorEnumA> {
|
||||||
|
Err(SomeErrorEnumA::BadCase)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn error_handle_00() {
|
||||||
|
assert_eq!(format!("{}", SomeErrorEnumA::BadCase), "BadCase");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn error_handle_01() {
|
||||||
|
assert_eq!(
|
||||||
|
format!("{}", SomeErrorEnumA::WithStringContent(format!("inner"))),
|
||||||
|
"WithStringContent"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn error_handle_02() {
|
||||||
|
assert_eq!(
|
||||||
|
format!(
|
||||||
|
"{}",
|
||||||
|
SomeErrorEnumA::WithStringContentFmt(format!("inner failure \"quoted\""))
|
||||||
|
),
|
||||||
|
"bad: inner failure \"quoted\""
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
pub mod binned;
|
pub mod binned;
|
||||||
|
pub mod databuffer_tools;
|
||||||
pub mod events;
|
pub mod events;
|
||||||
pub mod search;
|
pub mod search;
|
||||||
pub mod status;
|
pub mod status;
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
use crate::bodystream::response;
|
||||||
|
use crate::bodystream::BodyStream;
|
||||||
|
use crate::response_err;
|
||||||
|
use bytes::Bytes;
|
||||||
|
use err::thiserror;
|
||||||
|
use err::ToPublicError;
|
||||||
|
use futures_util::Stream;
|
||||||
|
use http::Method;
|
||||||
|
use http::Request;
|
||||||
|
use http::Response;
|
||||||
|
use http::StatusCode;
|
||||||
|
use hyper::Body;
|
||||||
|
use netpod::log::*;
|
||||||
|
use netpod::NodeConfigCached;
|
||||||
|
use netpod::ACCEPT_ALL;
|
||||||
|
use netpod::APP_JSON;
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
|
#[derive(Debug, thiserror::Error)]
|
||||||
|
pub enum FindActiveError {
|
||||||
|
#[error("HttpBadAccept")]
|
||||||
|
HttpBadAccept,
|
||||||
|
#[error("HttpBadUrl")]
|
||||||
|
HttpBadUrl,
|
||||||
|
#[error("{0}")]
|
||||||
|
Error(Box<dyn ToPublicError>),
|
||||||
|
#[error("{0}")]
|
||||||
|
UrlError(#[from] url::ParseError),
|
||||||
|
#[error("InternalError")]
|
||||||
|
InternalError,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToPublicError for FindActiveError {
|
||||||
|
fn to_public_error(&self) -> String {
|
||||||
|
match self {
|
||||||
|
FindActiveError::HttpBadAccept => format!("{self}"),
|
||||||
|
FindActiveError::HttpBadUrl => format!("{self}"),
|
||||||
|
FindActiveError::Error(e) => e.to_public_error(),
|
||||||
|
FindActiveError::UrlError(e) => format!("can not parse url: {e}"),
|
||||||
|
FindActiveError::InternalError => format!("{self}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct FindActiveHandler {}
|
||||||
|
|
||||||
|
impl FindActiveHandler {
|
||||||
|
pub fn handler(req: &Request<Body>) -> Option<Self> {
|
||||||
|
if req.uri().path() == "/api/4/tools/databuffer/findActive" {
|
||||||
|
Some(Self {})
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn handle(&self, req: Request<Body>, ncc: &NodeConfigCached) -> Result<Response<Body>, FindActiveError> {
|
||||||
|
if req.method() != Method::GET {
|
||||||
|
Ok(response(StatusCode::NOT_ACCEPTABLE)
|
||||||
|
.body(Body::empty())
|
||||||
|
.map_err(|_| FindActiveError::InternalError)?)
|
||||||
|
} else {
|
||||||
|
match Self::handle_req(req, ncc).await {
|
||||||
|
Ok(ret) => Ok(ret),
|
||||||
|
Err(e) => {
|
||||||
|
error!("{e}");
|
||||||
|
let res = response_err(StatusCode::NOT_ACCEPTABLE, e.to_public_error())
|
||||||
|
.map_err(|_| FindActiveError::InternalError)?;
|
||||||
|
Ok(res)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn handle_req(req: Request<Body>, ncc: &NodeConfigCached) -> Result<Response<Body>, FindActiveError> {
|
||||||
|
let accept_def = APP_JSON;
|
||||||
|
let accept = req
|
||||||
|
.headers()
|
||||||
|
.get(http::header::ACCEPT)
|
||||||
|
.map_or(accept_def, |k| k.to_str().unwrap_or(accept_def));
|
||||||
|
let url = {
|
||||||
|
let s1 = format!("dummy:{}", req.uri());
|
||||||
|
Url::parse(&s1)?
|
||||||
|
};
|
||||||
|
if accept.contains(APP_JSON) || accept.contains(ACCEPT_ALL) {
|
||||||
|
type _A = netpod::BodyStream;
|
||||||
|
Ok(Response::builder()
|
||||||
|
.status(StatusCode::OK)
|
||||||
|
.body(BodyStream::wrapped(Box::pin(DummyStream::new()), "find_active".into()))
|
||||||
|
.map_err(|_| FindActiveError::InternalError)?)
|
||||||
|
} else {
|
||||||
|
Err(FindActiveError::HttpBadAccept)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct DummyStream {}
|
||||||
|
|
||||||
|
impl DummyStream {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Stream for DummyStream {
|
||||||
|
type Item = Result<Bytes, crate::err::Error>;
|
||||||
|
|
||||||
|
fn poll_next(self: std::pin::Pin<&mut Self>, cx: &mut std::task::Context) -> std::task::Poll<Option<Self::Item>> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user