Mode:
Duration:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package main
import (
"fmt"
"log"
"net/http"
)
func loggingMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Println("Request:", r.Method, r.URL.Path)
next.ServeHTTP(w, r)
})
}
func homeHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Welcome!")
}
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", homeHandler)
fmt.Println("Server running at http://localhost:8080")
http.ListenAndServe(":8080", loggingMiddleware(mux))
}Coding works best on desktop or with an external keyboard.