diff --git a/Cargo.lock b/Cargo.lock index 905e898..61523b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -332,6 +332,15 @@ dependencies = [ "termcolor", ] +[[package]] +name = "envy" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f938a4abd5b75fe3737902dbc2e79ca142cc1526827a9e40b829a086758531a9" +dependencies = [ + "serde", +] + [[package]] name = "fake-simd" version = "0.1.2" @@ -2160,14 +2169,15 @@ dependencies = [ [[package]] name = "xesite" -version = "0.1.0" +version = "2.0.0" dependencies = [ "anyhow", "comrak", + "envy", "handlebars", - "log 0.4.8", + "log 0.3.9", "pretty_env_logger", - "rand 0.7.3", + "rand 0.6.5", "serde", "serde_dhall", "tokio", diff --git a/Cargo.toml b/Cargo.toml index 5ace328..a17dc2c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "xesite" -version = "0.1.0" +version = "2.0.0" authors = ["Christine Dodrill "] edition = "2018" @@ -9,6 +9,7 @@ edition = "2018" [dependencies] anyhow = "1" comrak = "0.7" +envy = "0.4" handlebars = "3.2.1" log = "0" pretty_env_logger = "0" diff --git a/src/app.rs b/src/app.rs new file mode 100644 index 0000000..0910cac --- /dev/null +++ b/src/app.rs @@ -0,0 +1,45 @@ +use crate::signalboost::Person; +use anyhow::Result; +use serde::Deserialize; +use std::path::PathBuf; + +mod defaults { + use std::path::PathBuf; + + pub fn clacks() -> Vec { + vec!["Ashlynn".to_string()] + } + + pub fn signalboost_fname() -> PathBuf { + "./signalboost.dhall".into() + } + pub fn port() -> u16 { + 34252 + } +} + +#[derive(Clone, Deserialize)] +pub struct Config { + #[serde(default = "defaults::clacks")] + clack_set: Vec, + #[serde(default = "defaults::signalboost_fname")] + signalboost_fname: PathBuf, + #[serde(default = "defaults::port")] + port: u16, +} + +#[derive(Clone)] +pub struct State { + pub cfg: Config, + pub signalboost: Vec, +} + +pub fn init<'a>() -> Result { + let cfg: Config = envy::from_env()?; + let sb = serde_dhall::from_file(cfg.signalboost_fname.clone()).parse()?; + + Ok(State { + cfg: cfg, + signalboost: sb, + }) +} diff --git a/src/main.rs b/src/main.rs index e7a11a9..d62e8e3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,23 @@ -fn main() { - println!("Hello, world!"); +use anyhow::Result; +use warp::Filter; + +pub mod app; +pub mod signalboost; + +const APPLICATION_NAME: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")); + +#[tokio::main] +async fn main() -> Result<()> { + pretty_env_logger::init(); + + let state = app::init()?; + + // GET /hello/warp => 200 OK with body "Hello, warp!" + let hello = warp::path!("hello" / String).map(|name| format!("Hello, {}!", name)); + + warp::serve(hello.with(warp::log(APPLICATION_NAME))) + .run(([127, 0, 0, 1], 3030)) + .await; + + Ok(()) } diff --git a/src/signalboost.rs b/src/signalboost.rs new file mode 100644 index 0000000..50ae49a --- /dev/null +++ b/src/signalboost.rs @@ -0,0 +1,12 @@ +use serde::Deserialize; + +#[derive(Clone, Debug, Deserialize)] +pub struct Person { + pub name: String, + pub tags: Vec, + + #[serde(rename = "gitLink")] + pub git_link: String, + + pub twitter: String, +}