package main
import (
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request){
w.Write([]byte("hello world"))
})
http.ListenAndServe(":8000", nil)
}
If I remove the *
in http.Request
:
github.com/creating_web_app_go/main.go:8: cannot use func literal (type func(http.ResponseWriter, http.Request)) as type func(http.ResponseWriter, *http.Request) in argument to http.HandleFunc
I'm very new to both Go and pointers.
So the Question is,
why must http.Request
be a pointer rather than a func literal
? Can anyone explain this in the simplest way possible, with perhaps a reference to source code?