less centralisation in code

This commit is contained in:
fungal 2023-12-18 11:54:21 +01:00
parent 09b26b3987
commit a9048f05bc
1 changed files with 17 additions and 12 deletions

29
main.go
View File

@ -14,23 +14,28 @@ type EmojiDetails struct {
//go:embed templates
var indexHTML embed.FS
func main() {
func handleForm(w http.ResponseWriter, r *http.Request) {
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
}
if r.Method != http.MethodPost {
tmpl.Execute(w, nil)
return
}
details := EmojiDetails{
Label: r.FormValue("label"),
}
details := EmojiDetails{
Label: r.FormValue("label"),
}
log.Print(details.Label)
log.Print(details.Label)
tmpl.Execute(w, struct{ Success bool }{true})
})
tmpl.Execute(w, struct{ Success bool }{true})
}
func setupRoutes() {
http.HandleFunc("/", handleForm)
http.ListenAndServe(":8080", nil)
}
func main() {
setupRoutes()
}