Commit 27ddfe9
Changed files (3)
cmd
web
main.go → cmd/web/handlers.go
@@ -1,7 +1,6 @@
package main
import (
- "log"
"net/http"
"regexp"
)
@@ -80,25 +79,4 @@ func isValidToken(token string) bool {
func about(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Server", "buylater.email")
w.Write([]byte("About - buylater.email helps you delay purchases and buy more intentionally"))
-}
-
-func main() {
- // Initialize a new servemux (router) - this stores the mapping between
- // URL patterns and their corresponding handlers.
- mux := http.NewServeMux()
-
- // Register handlers for buylater.email routes
- mux.HandleFunc("GET /{$}", home) // Exact match for home page
- mux.HandleFunc("GET /submit", submitForm) // Display email submission form
- mux.HandleFunc("POST /submit", processSubmit) // Process form submission
- mux.HandleFunc("GET /confirm/{token}", confirmWithToken) // Magic link confirmation with token
- mux.HandleFunc("GET t/about", about) // About page
-
- // Print a log message to indicate the server is starting.
- log.Printf("Starting server on http://localhost:4000")
-
- // Start the web server on port 4000. If ListenAndServe returns an error
- // we use log.Fatal() to log the error and terminate the program.
- err := http.ListenAndServe(":4000", mux)
- log.Fatal(err)
-}
+}
\ No newline at end of file
cmd/web/main.go
@@ -0,0 +1,27 @@
+package main
+
+import (
+ "log"
+ "net/http"
+)
+
+func main() {
+ // Initialize a new servemux (router) - this stores the mapping between
+ // URL patterns and their corresponding handlers.
+ mux := http.NewServeMux()
+
+ // Register handlers for buylater.email routes
+ mux.HandleFunc("GET /{$}", home) // Exact match for home page
+ mux.HandleFunc("GET /submit", submitForm) // Display email submission form
+ mux.HandleFunc("POST /submit", processSubmit) // Process form submission
+ mux.HandleFunc("GET /confirm/{token}", confirmWithToken) // Magic link confirmation with token
+ mux.HandleFunc("GET /about", about) // About page
+
+ // Print a log message to indicate the server is starting.
+ log.Printf("Starting server on http://localhost:4000")
+
+ // Start the web server on port 4000. If ListenAndServe returns an error
+ // we use log.Fatal() to log the error and terminate the program.
+ err := http.ListenAndServe(":4000", mux)
+ log.Fatal(err)
+}
\ No newline at end of file
.gitignore
@@ -1,2 +1,3 @@
docs/lets-go/*
buylater
+web