task/1.8
1package main
2
3import (
4 "log"
5 "net/http"
6)
7
8func main() {
9 // Initialize a new servemux (router) - this stores the mapping between
10 // URL patterns and their corresponding handlers.
11 mux := http.NewServeMux()
12
13 // Register handlers for buylater.email routes
14 mux.HandleFunc("GET /{$}", home) // Exact match for home page
15 mux.HandleFunc("GET /submit", submitForm) // Display email submission form
16 mux.HandleFunc("POST /submit", processSubmit) // Process form submission
17 mux.HandleFunc("GET /confirm/{token}", confirmWithToken) // Magic link confirmation with token
18 mux.HandleFunc("GET /about", about) // About page
19
20 // Print a log message to indicate the server is starting.
21 log.Printf("Starting server on http://localhost:4000")
22
23 // Start the web server on port 4000. If ListenAndServe returns an error
24 // we use log.Fatal() to log the error and terminate the program.
25 err := http.ListenAndServe(":4000", mux)
26 log.Fatal(err)
27}