I have a controller that doesn't depend on a external package, one example of it's method signature is
func (u *UserController) FindUserById(request struct{ id string }) (*UserProperties, error)
I need an adapter function that converts this signature of FindUserById into something Gin accepts (could be gorilla/mux, doesn't matter), something like this
func AdaptRoute(
handler any, // the handler function, usually a method of a struct
inputOfHandler any, // it will be main input of the handler
statusHTTP int,
) gin.HandlerFunc {
return func(c *gin.Context) {
// call handler function
// handler function can accept multiple arguments (the inputOfHandler and some authentication data, if needed)
// if returns error, then return a response with its status code
// if returns unknown error, return response 500 and "internal server error message"
}
}
I couldn't write the implementation of that function until now. Should I be doing another thing instead? The main reason I'm doing this is for decouple my controllers from an specific package