Move workspace crates into subfolder

This commit is contained in:
Dominik Werder committed 2023-07-10 14:45:25 +02:00
1 parent 8938e55f86
commit 30c7fcb1e5
212 files changed
+246 -41

No files matched your search

+1 -1
View File
@@ -1,5 +1,5 @@
[workspace]
members = ["daqbuffer", "httpret", "h5out", "items_proc", "nodenet", "httpclient", "dq"]
members = ["crates/*"]
[profile.release]
opt-level = 1
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -19,11 +19,11 @@ pub enum ConfigError {
Error,
}
impl fmt::Display for ConfigError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "ConfigError::{self:?}")
}
}
// impl fmt::Display for ConfigError {
// fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
// write!(fmt, "ConfigError::{self:?}")
// }
// }
impl From<ConfigParseError> for ConfigError {
fn from(value: ConfigParseError) -> Self {
File renamed without changes.
File renamed without changes.
@@ -17,6 +17,8 @@ pub mod read3;
pub mod read4;
pub mod streamlog;
pub use parse;
use bytes::Bytes;
use bytes::BytesMut;
use err::Error;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+5 -1
View File
@@ -4,6 +4,9 @@ version = "0.0.3"
authors = ["Dominik Werder <dominik.werder@gmail.com>"]
edition = "2021"
[lib]
doctest = false
[dependencies]
backtrace = "0.3"
serde = { version = "1.0", features = ["derive"] }
@@ -16,5 +19,6 @@ chrono = { version = "0.4", features = ["serde"] }
url = "2.2"
regex = "1.5"
http = "0.2"
thiserror = "1.0"
#thiserror = "1.0"
thiserror = { path = "../../../thiserror" }
anyhow = "1.0"
+48 -2
View File
@@ -2,6 +2,7 @@
pub use anyhow;
pub use thiserror;
pub use thiserror::Error as ThisError;
pub mod bt {
pub use backtrace::Backtrace;
@@ -20,13 +21,13 @@ use std::sync::PoisonError;
pub type Res2<T> = anyhow::Result<T>;
#[derive(Debug, thiserror::Error)]
#[derive(Debug, ThisError)]
pub enum ErrA {
#[error("bad-A")]
Bad,
}
#[derive(Debug, thiserror::Error)]
#[derive(Debug, ThisError)]
pub enum ErrB {
#[error("worse-B")]
Worse,
@@ -474,3 +475,48 @@ pub fn todoval<T>() -> T {
eprintln!("TODO\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\""
);
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,4 +1,5 @@
pub mod binned;
pub mod databuffer_tools;
pub mod events;
pub mod search;
pub mod status;
File renamed without changes.
+110
View File
@@ -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!()
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loaded 100 of 212 files, more files were not shown because too many files have changed in this diff. Show more