♻️ Extract crate ptth_core

main
_ 2020-11-27 00:03:11 +00:00
parent 64a0d90762
commit 84bb326f37
14 changed files with 48 additions and 32 deletions

View File

@ -14,7 +14,6 @@ aho-corasick = "0.7.14"
base64 = "0.12.3"
blake3 = "0.3.7"
chrono = "0.4.19"
ctrlc = { version = "3.1.7", features = [ "termination" ] }
dashmap = "3.11.10"
futures = "0.3.7"
handlebars = "3.5.1"
@ -41,6 +40,7 @@ ulid = "0.4.1"
url = "2.2.0"
always_equal = { path = "crates/always_equal" }
ptth_core = { path = "crates/ptth_core" }
[workspace]

View File

@ -0,0 +1,17 @@
[package]
name = "ptth_core"
version = "0.1.0"
authors = ["Trish"]
edition = "2018"
license = "AGPL-3.0"
[dependencies]
ctrlc = { version = "3.1.7", features = [ "termination" ] }
futures = "0.3.7"
hyper = "0.13.8"
serde = {version = "1.0.117", features = ["derive"]}
tokio = { version = "0.2.22", features = ["full"] }
tracing = "0.1.21"
tracing-futures = "0.2.4"

View File

@ -0,0 +1,16 @@
pub mod graceful_shutdown;
pub mod http_serde;
pub mod prelude;
// The arguments are in order so they are in order overall:
// e.g. prefix_match ("/prefix", "/prefix/middle/suffix") -> "/middle/suffix"
pub fn prefix_match <'a> (prefix: &str, hay: &'a str) -> Option <&'a str>
{
if hay.starts_with (prefix) {
Some (&hay [prefix.len ()..])
}
else {
None
}
}

View File

@ -0,0 +1,4 @@
pub use tracing::{
debug, error, info, trace, warn,
instrument,
};

View File

@ -18,11 +18,11 @@ use hyper::{
};
use serde::Deserialize;
use ptth::{
use ptth_core::{
http_serde::RequestParts,
prelude::*,
server::file_server,
};
use ptth::server::file_server;
#[derive (Default)]
pub struct Config {
@ -133,7 +133,7 @@ async fn main () -> Result <(), Box <dyn Error>> {
}
});
let (shutdown_rx, forced_shutdown) = ptth::graceful_shutdown::init_with_force ();
let (shutdown_rx, forced_shutdown) = ptth_core::graceful_shutdown::init_with_force ();
let server = Server::bind (&addr)
.serve (make_svc)

View File

@ -30,7 +30,7 @@ async fn main () -> Result <(), Box <dyn Error>> {
info! ("ptth_relay Git version: {:?}", ptth::relay::git_version::GIT_VERSION);
let (shutdown_rx, forced_shutdown) = ptth::graceful_shutdown::init_with_force ();
let (shutdown_rx, forced_shutdown) = ptth_core::graceful_shutdown::init_with_force ();
forced_shutdown.wrap_server (
relay::run_relay (

View File

@ -51,7 +51,7 @@ fn main () -> Result <(), Box <dyn Error>> {
rt.block_on (async move {
ptth::server::run_server (
config_file,
ptth::graceful_shutdown::init (),
ptth_core::graceful_shutdown::init (),
Some (path),
opt.asset_root
).await

View File

@ -5,24 +5,8 @@
pub const PTTH_MAGIC_HEADER: &str = "X-PTTH-2LJYXWC4";
pub mod graceful_shutdown;
pub mod http_serde;
pub mod prelude;
pub mod relay;
pub mod server;
// The arguments are in order so they are in order overall:
// e.g. prefix_match ("/prefix", "/prefix/middle/suffix") -> "/middle/suffix"
pub fn prefix_match <'a> (prefix: &str, hay: &'a str) -> Option <&'a str>
{
if hay.starts_with (prefix) {
Some (&hay [prefix.len ()..])
}
else {
None
}
}
#[cfg (test)]
mod tests;

View File

@ -1 +0,0 @@
pub use tracing::{debug, error, info, trace, warn};

View File

@ -40,14 +40,11 @@ use tokio::{
},
time::delay_for,
};
use tracing::{
debug, error, info, trace,
instrument,
};
use crate::{
use ptth_core::{
http_serde,
prefix_match,
prelude::*,
};
pub mod config;

View File

@ -36,7 +36,7 @@ use always_equal::test::AlwaysEqual;
#[cfg (not (test))]
use always_equal::prod::AlwaysEqual;
use crate::{
use ptth_core::{
http_serde::{
Method,
Response,
@ -796,9 +796,8 @@ mod tests {
#[test]
fn file_server () {
use crate::{
use ptth_core::{
http_serde::Method,
//prelude::*,
};
use super::*;

View File

@ -17,7 +17,7 @@ use tokio::{
time::delay_for,
};
use crate::{
use ptth_core::{
http_serde,
prelude::*,
};