feat: initial impl

This commit is contained in:
əlemi 2023-11-14 05:29:02 +01:00
parent 5cb8a50faf
commit 691baa42ba
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 20 additions and 0 deletions

9
Cargo.toml Normal file
View file

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

11
src/main.rs Normal file
View file

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