What you're looking for is reflect.Type.NumIn()int and reflect.Type.In(i int) Type. See example here https://play.golang.org/p/q1D56Abj-5
On Tuesday, March 21, 2017 at 12:01:09 AM UTC+1, Tyler Compton wrote: > > I'm trying to create an HTTP request router library that automatically > decodes parameters in the request URL and passes them as arguments to the > handler function. It would theoretically make something like this possible: > > myRouter.HandleFunc("/getPuppies/{id}", func(w http.ResponseWriter, r * > http.Request, id string) { > // Handle the request > }); > > I am aware that you can't get the name of a function's arguments. That's > okay with me, I can just pass the params in the order they appear. However, > I do need to be able to check how many arguments a function has and what > the types of those arguments are, so I can type assert the parameters and > give sane error messages when the user makes a mistake. > > Before you point out that this is a bad idea and that reflection is never > clear, I am fully aware! I'm doing this to learn about reflection in Go and > to see if Go can support a workflow something like Java's JAX-RS. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.