Any open source library wants to use generics, thus one can volunteer some time?

Thinking about generics and Go 1.18, I figure many libraries will want to release versions that make use of generics.

Is there a list, on this forum, of open source libraries and projects that one can volunteer to ?

No. But off the top of my head I know that gorilla/mux needs a new maintainer and is looking for contributors:

Might be a good place to start! That’s a very popular library. If I had more time I would be contributing there (I use gorilla/mux in production). Not sure if/how generics could help there. But I find myself writing this same code a lot:

// Route
router.Path("/foo").Methods("GET").HandlerFunc(MyRouteHandler)

// Handler
func MyRouteHandler(w http.ResponseWriter, r *http.Request) {
	var payload SomePayload
	if err := json.NewDecoder(r.Body).Decode(&payload); err != nil {
		// BadRequest is a helper to send a bad request back on w
		BadRequest("Bad params", w)
		return
	}
	// The happy path. Do work here...
}

It would be pretty handy to have a generic function that sat between my HandleFunc and the router that handled this for me. So, by the time I get to my HandleFunc I already know the payload is validated and I have a decoded struct. Something like a JSONHandlerFunc[T] that expects the request body to be JSON and handles the boilerplate of deserializing it and dealing with errors? That could also be middleware perhaps (just add it to request context?). Anyway, then I could rewrite my handler to:

// Route
router.Path("/foo").Methods("GET").JSONHandlerFunc[SomePayload](MyRouteHandler)

// Handler
func MyRouteHandler(w http.ResponseWriter, r *http.Request, payload SomePayload) {
	// The happy path. Do work here...
}

It might be controversial to have that much “magic” in the toolkit, but this is something I can think of off the top of my head where it would cut down on boilerplate and provide value (to me at least!). I actually implemented something similar to this using stdlib here:

Hi @Dean_Davidson ,

I use gorilla/mux in production as well ! Thx for pointing this out, I was not aware they are looking for maintainers.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.