1
0
mirror of https://github.com/dpc/tagwiki synced 2024-06-26 06:43:14 +00:00
tagwiki/src/main.rs

46 lines
875 B
Rust
Raw Normal View History

2020-05-01 08:11:21 +00:00
//! tagwiki
2020-03-08 23:36:52 +00:00
2020-05-01 08:11:21 +00:00
use anyhow::Result;
use log::info;
2020-03-08 23:36:52 +00:00
use structopt::StructOpt;
2020-05-01 08:11:21 +00:00
use warp::{path::FullPath, Filter};
2020-03-08 23:36:52 +00:00
/// Command line options
mod cli;
2020-05-01 08:11:21 +00:00
/// Page
mod page;
2020-03-08 23:36:52 +00:00
2020-05-01 08:11:21 +00:00
mod index;
/// Utils
mod util;
async fn handler(path: FullPath) -> Result<String, std::convert::Infallible> {
let tags: Vec<_> = path
.as_str()
.split('/')
.map(|t| t.trim())
.filter(|t| t != &"")
.collect();
Ok(format!("Path: {:?}", tags))
}
fn start(opts: &cli::Opts) -> Result<()> {
let handler = warp::path::full().and_then(handler);
let serve = warp::serve(handler).run(([127, 0, 0, 1], opts.port));
info!("Listening on port {}", opts.port);
tokio::runtime::Runtime::new().unwrap().block_on(serve);
2020-03-08 23:36:52 +00:00
Ok(())
}
2020-05-01 08:11:21 +00:00
2020-03-08 23:36:52 +00:00
fn main() -> Result<()> {
env_logger::init();
let opts = cli::Opts::from_args();
2020-05-01 08:11:21 +00:00
start(&opts)?;
2020-03-08 23:36:52 +00:00
Ok(())
}