jeudi 28 janvier 2016

How to reflect dynamic method name of an object in Golang

example

router.Get(path, handler) // works fine

methodStr = "Get"    
router.methodStr(path, handler) // error

funcs := map[string]func(){"methodStr": "Get"}
router.funcs["methodStr"](path, handler) // error

reflect.ValueOf(router).MethodByName("Get").Call([]reflect.Value{}) // error

I am getting method names as strings. How to call the router object methods with string names





Aucun commentaire:

Enregistrer un commentaire