The method expression (*Api).ListHandler
yields a function with the signature func(*Api, http.ResponseWriter, *http.Request) To use the method value with the signature func(http.ResponseWriter, *http.Request) you need an instance of `*Api` to call its method, so you can't assign the handler to the route until after you've initialized the `*Api`. Don't try to initialize the routes in their top-level declaration, create the Api, then create the routes. On Friday, March 3, 2017 at 10:33:24 AM UTC-5, Dave wrote: > > Hi everyone, > > I just got started with GO and decided to attempt building an HTTP API > package using Gorilla Mux for an existing backend. > Unfortunately i have gotten stuck on an issue with initializing my routes > for the past couple of days. I tried searching for a solution online and > have read a ton of articles/tutorials but have not found exactly what i am > trying to do. > > The code is a little big to just paste and since it uses an external > import which play.golang does not support i attached it. > > My code does not compile returning: > ./main.go:40: cannot use (*Api).ListHandler (type func(*Api, http. > ResponseWriter, *http.Request)) as type http.HandlerFunc in field value > > Now i sort of understand why it says this because my ListHandler does not > adhere to the http.HandlerFunc signature as it is part of my Api struct but > this is where i am stuck. > > Any ideas on how to make this work or should i be doing something > completely different. > > (There could be some pointer errors here and there, i am still struggling > with those so try to overlook them :P and i mocked the backend struct as it > is in my opinion not relevant to the issue) > > - Dave > -- 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.