On Thu, Aug 6, 2020 at 7:23 PM <dola...@gmail.com> wrote: > > I'm quite happy about the generics so far, but now I'm trying some ideas that > I don't know if they are possible or not given the current proposal. > My idea, is to create some kind of generic handler for "net/http" that could > be used in a whole project. > It would allow same behavior on each routes (unmarshalling the request, > validating it, calling the real business logic with a func(Request) > (Response, error) style, handling the business logic error, marshalling the > response). > This is currently impossible (that I know) without using some bad hacks > (using an unmarshalling middleware and storing it in the context.Context), > etc. > > So here is my attempt using generics, but my example stopped on this error: > > https://go2goplay.golang.org/p/NyvV47ozr7S
I don't understand how using generics with the current net/http package will let you avoid the hacks that you mention. The type errors your example encounters are due to the mismatch of converting from an interface based approach to a type based approach. I don't know that there is going to be any workable solution here. Ian -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXM7y%3DbRO%3DTB4r14XULs4wJG-Uq5cfKnU4Rfds5kW5%3DNw%40mail.gmail.com.