4 ms·
Of course you could use Negroni with Gin. Anyway, Gin is a full-featured framework on top of httpRouter, I will explain this later (eventually I would like to m
by manucorporat 12y ago
Of course you could use Negroni with Gin. Anyway, Gin is a full-featured framework on top of httpRouter, I will explain this later (eventually I would like to merge both in the future, removing one abstraction layer and tunning the performance).
Gin is also a better fit for httpRouter, it's not designed to fit any other framework. I wanted Gin to share the same philosophy than HttpRouter. Basically the Gin/HttpRouter community cares about performance, so you don't. For example in Gin, you can created thousands of nested groups and the performance will be still the same.
Gin is full-featured, to me it means: control flow, middlewares, error management (errors and panics both), easy rendering, easy validation, easy data passing between middlewares. For example you can collect errors (not only panics) and then send them to Sentry easily.
The control flow is interesting: if a middleware calls c.Abort(code) or c.Fail(code, message), the rest handlers in the chain would never be called, this is very useful when authorisation is required. https://github.com/gin-gonic/gin/blob/master/auth.go#L76 https://github.com/gin-gonic/gin/blob/master/auth.go#L76
Of course authorisation can be just applied to a group, you can see example in the github page. Per-group middlwares and even per-request middlewares!
We added all that features without making it significantly slower (compared to httprouter) and for sure that overhead will be reduced in upcoming releases (no API changes). If you want to use HttpRouter and you also want cool features, in my opinion Gin is one of the best choices. Just try it.
- im_dario 12y agoI don't think Negroni and Gin will mix well</pun> I implemented almost the same features as Negroni's middlewares [0] in my project (a backend for grassroots referendums). I was even asked to do a Sentry middleware [1] to improve it. I would advise you against merging projects. It would be great if you separate the route grouping code and release it as an independent library to build on httprouter (even merging them) and keep Gin as it is. Although, my question was performance-wise because I think Negroni will be similar in performance. [0] https://github.com/imdario/minshu/blob/master/minshu-server/http.go https://github.com/imdario/minshu/blob/master/minshu-server/... [1] https://github.com/imdario/minshu/issues/1 https://github.com/imdario/minshu/issues/1
- katokay 12y agoIt looks promising. However, it is making the same mistake many of the other frameworks are making in that in order to make middleware, you must take on a dependency for this framework and re-implement all middleware for this specific framework. The larger community needs to discuss and agree upon what middleware is and start using those implicit interfaces they're so fond of.