这里有以下功能.我注意到最后一个参数是用_.这种模式的目的是什么?
func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
fmt.Fprint(w, "Welcome!\n")
}
Run Code Online (Sandbox Code Playgroud)
小智 11
它意味着"忽略那个参数",这里他们仍然需要最后一个参数的原因是因为他们想把它传递type Handle给GET具有签名的函数:
type Handle func(http.ResponseWriter, *http.Request, Params)
如果你只是传递类似的东西func Index(w http.ResponseWriter, r *http.Request)将不被视为type Handle.