From 09b26b3987e047e4a3aa6718a93de81b21c72c27 Mon Sep 17 00:00:00 2001 From: fungal Date: Mon, 18 Dec 2023 11:46:41 +0100 Subject: [PATCH] /dev/null --- go.mod | 3 +++ main.go | 36 ++++++++++++++++++++++++++++++++++++ templates/index.html | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 go.mod create mode 100644 main.go create mode 100644 templates/index.html diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..2786177 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module myceliumlab/emojiquest + +go 1.21.4 diff --git a/main.go b/main.go new file mode 100644 index 0000000..36a9197 --- /dev/null +++ b/main.go @@ -0,0 +1,36 @@ +package main + +import ( + "embed" + "html/template" + "log" + "net/http" +) + +type EmojiDetails struct { + Label string +} + +//go:embed templates +var indexHTML embed.FS + +func main() { + tmpl := template.Must(template.ParseFS(indexHTML, "templates/index.html")) + + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodPost { + tmpl.Execute(w, nil) + return + } + + details := EmojiDetails{ + Label: r.FormValue("label"), + } + + log.Print(details.Label) + + tmpl.Execute(w, struct{ Success bool }{true}) + }) + + http.ListenAndServe(":8080", nil) +} diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..dadd7d2 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,32 @@ + + + + + + Emoji Request + + + + +
+ {{if .Success}} +

emoji requested successfully

+ {{end}} +

Request An Emoji

+
+ + + + + +
+ +
+ + \ No newline at end of file