start adding basic app modules

This commit is contained in:
Cadey Ratio 2020-07-12 14:42:09 -04:00
parent edf4888534
commit 778bd133e8
5 changed files with 94 additions and 6 deletions

16
Cargo.lock generated
View File

@ -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",

View File

@ -1,6 +1,6 @@
[package]
name = "xesite"
version = "0.1.0"
version = "2.0.0"
authors = ["Christine Dodrill <me@christine.website>"]
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"

45
src/app.rs Normal file
View File

@ -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<String> {
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<String>,
#[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<Person>,
}
pub fn init<'a>() -> Result<State> {
let cfg: Config = envy::from_env()?;
let sb = serde_dhall::from_file(cfg.signalboost_fname.clone()).parse()?;
Ok(State {
cfg: cfg,
signalboost: sb,
})
}

View File

@ -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(())
}

12
src/signalboost.rs Normal file
View File

@ -0,0 +1,12 @@
use serde::Deserialize;
#[derive(Clone, Debug, Deserialize)]
pub struct Person {
pub name: String,
pub tags: Vec<String>,
#[serde(rename = "gitLink")]
pub git_link: String,
pub twitter: String,
}