[英]Golang - Why this error happened in ServeHTTP Function : reflect: call of reflect.Value.Call on zero Value
我的代碼和錯誤消息在這里: https : //gist.github.com/WithGJR/a700e5d5bd35b5c8eef2
誰能為我解釋為什么會發生此錯誤,以及如何解決? 謝謝。
由於value.MethodByName(info.controllerMethodName)
可能返回無效方法,因此應檢查method.IsValid()
。
當發生這種情況時,您開始添加一堆log.Println
以查看發生了什么,直到引入適當的調試器為止。
//編輯
router.Get("/", controllers.IndexController{}, "Index")
您正在傳遞一個值, func (this *IndexController) Index()
是在指針上定義的,因此您的MethodByName
無法正常工作,請更改您的router.Get
。
router.Get("/", &controllers.IndexController{}, "Index")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.