all repos — guesser @ 29929154fd1212d1916e2a08dd7b52049c29ba5d

main.go (view raw)

 1package main
 2
 3import (
 4	"embed"
 5	"fmt"
 6	"net/http"
 7)
 8
 9//go:embed index.html
10var indexPage embed.FS
11
12func setupRoutes() {
13	http.HandleFunc("GET /", serveHTML)
14	http.HandleFunc("POST /", processHandler)
15}
16
17func main() {
18	setupRoutes()
19	fmt.Println("Server in ascolto su :3000")
20	http.ListenAndServe(":3000", nil)
21}
22
23func serveHTML(w http.ResponseWriter, r *http.Request) {
24	html, err := indexPage.ReadFile("index.html")
25	if err != nil {
26		http.Error(w, "Errore durante il caricamento del form HTML", http.StatusInternalServerError)
27		return
28	}
29
30	w.Header().Set("Content-Type", "text/html")
31	w.Write(html)
32}