mirror of
https://git.alemi.dev/mood.git
synced 2024-11-21 16:14:48 +01:00
feat: initial impl
This commit is contained in:
parent
5cb8a50faf
commit
691baa42ba
2 changed files with 20 additions and 0 deletions
9
Cargo.toml
Normal file
9
Cargo.toml
Normal 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
11
src/main.rs
Normal 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);
|
||||
}
|
Loading…
Reference in a new issue