Came accross the below function here. I noticed the last parameter is identified with _
. What is the intent of this pattern?
func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
fmt.Fprint(w, "Welcome!
")
}
Came accross the below function here. I noticed the last parameter is identified with _
. What is the intent of this pattern?
func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
fmt.Fprint(w, "Welcome!
")
}
It means "ignore that parameter", the reason that they still need the last parameter here is because they want to pass it as type Handle
to the function GET
, which has the signature:
type Handle func(http.ResponseWriter, *http.Request, Params)
If you simply pass something like func Index(w http.ResponseWriter, r *http.Request)
it will not be treated as type Handle
.