Commit e4cdb11
Changed files (2)
docs
todo
docs/todo/task_1.2.md
@@ -88,7 +88,14 @@ Web server starts cleanly, logs startup message, and serves requests through pro
## Implementation Log
-*Will be updated during implementation*
+### 2025-07-20 - Implementation Complete
+- Enhanced handler function with proper documentation explaining its role
+- Improved ServeMux initialization with clear comments about router functionality
+- Enhanced logging with more informative startup message including full URL
+- Added comprehensive comments explaining the three essential web application components
+- Improved code organization and readability while maintaining functionality
+- Verified code formatting with `go fmt` and `go vet`
+- Build successful with `go build`
---
main.go
@@ -5,15 +5,25 @@ import (
"net/http"
)
+// home is our handler function which writes a "Hello World" response.
+// It demonstrates the handler component of our web application.
func home(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello World"))
}
func main() {
+ // Initialize a new servemux (router) - this stores the mapping between
+ // URL patterns and their corresponding handlers.
mux := http.NewServeMux()
+
+ // Register the home function as the handler for the "/" URL pattern.
mux.HandleFunc("/", home)
- log.Print("starting server on :4000")
+ // 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)
}