krsoninikhil / go-rest-kit

FastAPI like controllers for gin based Go apps. Ready made packages for quickly setting up REST APIs in Go
https://nikhilsoni.me/2024/05/27/fastapi-like-controllers-for-gin-based-go-apps/
MIT License
9 stars 1 forks source link

Some bugs in crud/router.go #1

Open zhqqqy opened 1 month ago

zhqqqy commented 1 month ago

Hello, I have noticed some issues in your code.

krsoninikhil commented 3 days ago

Hey @zhqqqy, thanks for going though code and noticing the problems.

The correct handler method is defined here which uses generic to avoid the problem you highlighted with any type, along with the bind methods which check for the request type being nil, so it would only parse the body if caller is expecting the body.

The crud/router.go file is something I was trying by defining a separate router itself rather than defining the wrapper methods for handler. This didn't work out as expected because apparently the method can use only the generic type which are defined as part of struct itself and not dynamically during method call. That's why I restructured it as wrapper methods (here, and here for crud) which takes the handler as argument and returns the gin handler. I missed to remove this file from package, it's removed now. Thanks for highlighting.