emojiquest/main.go
2023-12-18 12:56:51 +01:00

45 lines
694 B
Go

package main
import (
"embed"
"html/template"
"log"
"net/http"
)
type EmojiDetails struct {
Label string
Url 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"),
Url: r.FormValue("url"),
}
log.Print(details.Label)
log.Print(details.Url)
tmpl.Execute(w, struct{ Success bool }{true})
}
func setupRoutes() {
http.HandleFunc("/", handleForm)
http.ListenAndServe(":8080", nil)
}
func main() {
setupRoutes()
}