diff --git a/Cargo.lock b/Cargo.lock index 2940d9a..13dbd7c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -449,6 +449,7 @@ dependencies = [ "serde 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)", + "toml 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 3706cb8..deda6dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ rocket_codegen = "0.3.6" serde = "1.0" serde_derive = "1.0" serde_json = "1.0" +toml = "0.4" [dependencies.rocket_contrib] version = "*" diff --git a/config.toml b/config.toml new file mode 100644 index 0000000..3b18ea1 --- /dev/null +++ b/config.toml @@ -0,0 +1 @@ +title = "Online Pinboard" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index d431ff4..eacb45c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,19 +10,37 @@ extern crate rocket_contrib; extern crate serde_derive; #[macro_use] extern crate serde_json; +extern crate toml; mod handlers; mod models; use rocket::Rocket; +use std::fs::File; +use std::io::prelude::*; use std::sync::RwLock; type NoteStore = RwLock>; +#[derive(Debug, Deserialize)] +struct Config { + title: String, +} + fn rocket(notes_path: Option<&str>) -> Rocket { + let mut config_data = String::new(); + let mut config_file = File::open("config.toml").expect("Cannot find config file: config.toml"); + config_file + .read_to_string(&mut config_data) + .expect("Cannot read config file: config.toml"); + let config: Config = + toml::from_str(&config_data).expect("Cannot parse config file: config.toml"); + let notes = models::note::Note::load_all(notes_path); + rocket::ignite() .manage(RwLock::new(notes)) + .manage(config) .mount( "/", routes![handlers::home::index, handlers::static_files::all],