less centralisation in code
This commit is contained in:
parent
09b26b3987
commit
a9048f05bc
29
main.go
29
main.go
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue