mirror of
https://codeberg.org/mycelium/emojiquest.git
synced 2024-11-17 14:39:14 +00:00
42 lines
627 B
Go
42 lines
627 B
Go
package main
|
|
|
|
import (
|
|
"embed"
|
|
"html/template"
|
|
"log"
|
|
"net/http"
|
|
)
|
|
|
|
type EmojiDetails struct {
|
|
Label string
|
|
}
|
|
|
|
//go:embed templates
|
|
var indexHTML embed.FS
|
|
|
|
func handleForm(w http.ResponseWriter, r *http.Request) {
|
|
tmpl := template.Must(template.ParseFS(indexHTML, "templates/index.html"))
|
|
|
|
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})
|
|
}
|
|
|
|
func setupRoutes() {
|
|
http.HandleFunc("/", handleForm)
|
|
http.ListenAndServe(":8080", nil)
|
|
}
|
|
|
|
func main() {
|
|
setupRoutes()
|
|
}
|