]> git.scottworley.com Git - voter/commitdiff
Start with the cgi example usage
authorScott Worley <scottworley@scottworley.com>
Fri, 18 Nov 2022 19:35:44 +0000 (11:35 -0800)
committerScott Worley <scottworley@scottworley.com>
Fri, 18 Nov 2022 19:39:11 +0000 (11:39 -0800)
.gitignore [new file with mode: 0644]
Cargo.lock [new file with mode: 0644]
Cargo.toml [new file with mode: 0644]
src/main.rs [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..ea8c4bf
--- /dev/null
@@ -0,0 +1 @@
+/target
diff --git a/Cargo.lock b/Cargo.lock
new file mode 100644 (file)
index 0000000..37716a9
--- /dev/null
@@ -0,0 +1,48 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "bytes"
+version = "1.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db"
+
+[[package]]
+name = "cgi"
+version = "0.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a71d44b66aa4d9229907c0126271215210037fc179437a2e92746ba6bc6e0a00"
+dependencies = [
+ "http",
+]
+
+[[package]]
+name = "fnv"
+version = "1.0.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
+
+[[package]]
+name = "http"
+version = "0.2.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399"
+dependencies = [
+ "bytes",
+ "fnv",
+ "itoa",
+]
+
+[[package]]
+name = "itoa"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc"
+
+[[package]]
+name = "voter"
+version = "0.1.0"
+dependencies = [
+ "cgi",
+]
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644 (file)
index 0000000..c819d86
--- /dev/null
@@ -0,0 +1,11 @@
+[package]
+name = "voter"
+version = "0.1.0"
+edition = "2021"
+authors = ["Scott Worley <scottworley@scottworley.com>"]
+description = "A simple web page that tracks votes"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+cgi = "0"
diff --git a/src/main.rs b/src/main.rs
new file mode 100644 (file)
index 0000000..574d43f
--- /dev/null
@@ -0,0 +1,7 @@
+fn respond(request: cgi::Request) -> Result<cgi::Response, String> {
+    let greeting = std::fs::read_to_string("greeting.txt").map_err(|_| "Couldn't open file")?;
+
+    Ok(cgi::text_response(200, greeting))
+}
+
+cgi::cgi_try_main! { respond }