emojiquest/main.go

37 lines
576 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
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)
}