/dev/null

This commit is contained in:
fungal 2023-12-18 11:46:41 +01:00
commit 09b26b3987
3 changed files with 71 additions and 0 deletions

3
go.mod Normal file
View file

@ -0,0 +1,3 @@
module myceliumlab/emojiquest
go 1.21.4

36
main.go Normal file
View file

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

32
templates/index.html Normal file
View file

@ -0,0 +1,32 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Emoji Request</title>
<style>
main {
max-width: 70ch;
padding: 2rem;
margin: auto;
}
</style>
</head>
<body>
<main>
{{if .Success}}
<h1>emoji requested successfully</h1>
{{end}}
<h1>Request An Emoji</h1>
<form method="POST">
<span>
<label for="emojiLabel">Emoji label</label>
<input type="text" id="emojiLabel" name="label" placeholder="blobcatNotLikeThis">
</span>
<input type="submit">
</form>
</body>
</main>
</html>