我的代码和错误消息在这里: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")