diff --git a/src/cli/log.rs b/src/cli/log.rs index 3e4118a4..76b5aa11 100644 --- a/src/cli/log.rs +++ b/src/cli/log.rs @@ -1,10 +1,5 @@ -extern crate chrono; -extern crate fern; -extern crate log; -extern crate std; - -use self::fern::colors::Color; -use self::fern::colors::ColoredLevelConfig; +use fern::colors::Color; +use fern::colors::ColoredLevelConfig; pub fn init(verbosity: usize) { let levels = ColoredLevelConfig::new() diff --git a/src/cli/start.rs b/src/cli/start.rs index 8f6276e7..ba3bdc1e 100644 --- a/src/cli/start.rs +++ b/src/cli/start.rs @@ -16,11 +16,16 @@ Y88b d88P Y88b 888 888 888 Y8b. 888 888 888 888 .d88P 888 d88P "; pub fn init(matches: &clap::ArgMatches) -> Result<(), Error> { + // output SurrealDB logo println!("{}", LOGO); + // Parse the database endpoint path + let path = matches.value_of("path").unwrap(); + // Parse the server binding address + let bind = matches.value_of("bind").unwrap(); // Start up the kvs storage - kvs::init(matches)?; + kvs::init(path)?; // Start up the web server - net::init(matches)?; + net::init(bind)?; // Don't error when done Ok(()) } diff --git a/src/kvs/mod.rs b/src/kvs/mod.rs index dd862926..2060c719 100644 --- a/src/kvs/mod.rs +++ b/src/kvs/mod.rs @@ -24,9 +24,7 @@ pub enum Transaction<'a> { static DB: OnceCell = OnceCell::new(); -pub fn init(conf: &clap::ArgMatches) -> Result<(), Error> { - // Parse the database endpoint path - let path = conf.value_of("path").unwrap(); +pub fn init(path: &str) -> Result<(), Error> { // Instantiate the database endpoint match path { "memory" => { diff --git a/src/net/mod.rs b/src/net/mod.rs index 7de33218..36117b51 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -22,13 +22,11 @@ use warp::Filter; const ID: &'static str = "Request-Id"; #[tokio::main] -pub async fn init(conf: &clap::ArgMatches) -> Result<(), Error> { +pub async fn init(bind: &str) -> Result<(), Error> { // - let adr = conf.value_of("bind").unwrap(); - // - let adr: SocketAddr = adr.parse().expect("Unable to parse socket address"); - // - let web = root::config() + let adr: SocketAddr = bind.parse().expect("Unable to parse socket address"); + + let net = root::config() // Version endpoint .or(version::config()) // Status endpoint @@ -52,22 +50,22 @@ pub async fn init(conf: &clap::ArgMatches) -> Result<(), Error> { // End routes setup ; - let web = web.with(warp::compression::gzip()); + let net = net.with(warp::compression::gzip()); - let web = web.with(head::server()); + let net = net.with(head::server()); - let web = web.with(head::version()); + let net = net.with(head::version()); - let web = web.map(|reply| { + let net = net.map(|reply| { let val = Uuid::new_v4().to_string(); warp::reply::with_header(reply, ID, val) }); - let web = web.with(log::write()); + let net = net.with(log::write()); info!("Starting web server on {}", adr); - warp::serve(web).run(adr).await; + warp::serve(net).run(adr).await; Ok(()) }