emojiquest/main.go

42 lines
627 B
Go
Raw Normal View History

2023-12-18 10:46:41 +00:00
package main
import (
"embed"
"html/template"
"log"
"net/http"
)
type EmojiDetails struct {
Label string
}
//go:embed templates
var indexHTML embed.FS
2023-12-18 10:54:21 +00:00
func handleForm(w http.ResponseWriter, r *http.Request) {
2023-12-18 10:46:41 +00:00
tmpl := template.Must(template.ParseFS(indexHTML, "templates/index.html"))
2023-12-18 10:54:21 +00:00
if r.Method != http.MethodPost {
tmpl.Execute(w, nil)
return
}
2023-12-18 10:46:41 +00:00
2023-12-18 10:54:21 +00:00
details := EmojiDetails{
Label: r.FormValue("label"),
}
2023-12-18 10:46:41 +00:00
2023-12-18 10:54:21 +00:00
log.Print(details.Label)
2023-12-18 10:46:41 +00:00
2023-12-18 10:54:21 +00:00
tmpl.Execute(w, struct{ Success bool }{true})
}
2023-12-18 10:46:41 +00:00
2023-12-18 10:54:21 +00:00
func setupRoutes() {
http.HandleFunc("/", handleForm)
2023-12-18 10:46:41 +00:00
http.ListenAndServe(":8080", nil)
}
2023-12-18 10:54:21 +00:00
func main() {
setupRoutes()
}