I'm trying to learn go for web programming. I came across the http.HandleFunc
function , to which i could provide a callback to handle the web request configured to it.
My small program looks like the following.
package main
import (
"fmt"
"log"
"net/http"
"sync"
)
var count int
var mu sync.Mutex
func main() {
var p Point
http.HandleFunc("/", handler)
log.Fatal(http.ListenAndServe("localhost:8080", nil))
}
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "URL.Path =:%q\n", r.URL.Path)
}
Why is the *http.Request in the handler
method a pointer? . I understand that this is how the designed it. But I would like to know why they are mandating a pointer instead of a regular value.