I want to implement MVC in golang. But it seems like hard to achieve what I want. in Testcontroller.go I have:
func (c *TestController) Test() {
//
}
func (c *TestController) Index() {
//
}
With only a controller, I can use reflect.ValueOf(TestController{}).MethodByName().Call() to execute that function. now I want to add another controller. but It seems like I can't new different instance by different string:
controllerName := strings.Split(r.URL.Path, "/")
controller = reflect.ValueOf(controllerName[1])
I know this is totaly wrong, but I hope I can get a TestController instance if controllerName == "Test" and get a IndexController instance if controllerName == "Index", using reflect seems can't achieve what I want. Is there any way to do is? Thank you very much!