diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..ec668c9 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "mood-cgi" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +rand = "0.8.5" diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..d9397e6 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,11 @@ +use rand::seq::IteratorRandom; + +fn main() { + let file = std::env::var("MOOD_FILE").unwrap_or("/srv/http/api/mood.txt".to_string()); + let content = std::fs::read_to_string(file).unwrap(); + let choice = content.lines().choose(&mut rand::thread_rng()).unwrap(); + + println!("Content-type: application/json"); + println!(); + println!("{{\"mood\":\"{}\"}}", choice); +}