gin-gonic / gin

Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.
https://gin-gonic.com/
MIT License
79.05k stars 8.03k forks source link

Issues/Improvements found after working with gin for a while #1198

Open huttarichard opened 6 years ago

huttarichard commented 6 years ago

I found few issues as I was adopting gin into our environment. Im pretty sure some of them has been address already. I solve these issues on my own, have solution for all of them but its not compatible with API gin provides right now. Everything is against master branch.

1) Bind json Method Not sure about custom parser gin is using as dependency... But decoder is not best solution. https://ahmet.im/blog/golang-json-decoder-pitfalls/

2) Validator Validator should not be part of gin. I suggest rather define interface for validations and use interface to validate. github.com/go-playground/validator brings github.com/go-playground/universal-translator that brings this github.com/go-playground/locales and probably others you get the idea why this is not cool

3) Write Headers Now Lets say you have stack of middlewares and on top there is one handling errors. if you AbortWithStatus somewhere is stack, this will write headers and error middleware has no chance to change headers after that.

maybe better here https://github.com/gin-gonic/gin/blob/master/gin.go#L320 ?

4) HTTP router I found the issue already somewhere I think /resource/:id /resource/batch are not working together. Honestly I did not fix this one for myself, no need, but still issue.

Let me know what do you think... Regards.

thinkerou commented 6 years ago

@huttarichard I agree with 2(but what's default validator?), and 4 have found one issue(httprouter also).