I suggest you also take a look at the Go spec that describes method values: https://golang.org/ref/spec#Method_values It seems to click on what you want to do. Also, take a look at this article from Alex Edwards: http://www.alexedwards.net/blog/organising-database-access more specifically, the "Dependency Injection" part. Look at how he takes the method booksIndex from a struct and is still able to reference to *Env in the handler.
Regards, Bruno Em terça-feira, 26 de julho de 2016 21:37:13 UTC-3, nakot...@gmail.com escreveu: > > Lets say an example function like this > > func (r *Router) Get(path string, controller interface{}) {} > > And I am calling it this way > > Route.Get("/", controllers.Test.IsWorking) > > > > Refering to this function > > type Test struct { > Name string > } > > > func (t Test) IsWorking() { > log.Println("hello") > } > > How can I get what struct is the function using? I mean on this example > the struct would be Test and the function IsWorking... I have no idea how > to achieve this > > Running a reflect TypeOf to controller returns this > > func(controllers.Test) > > But I am not sure how to create a reflect.New of the type of > controller.Test (without knowing about it) > -- 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.