How to break-out of martini middleware

97 views
Skip to first unread message

al...@oresoftware.com

unread,
Mar 14, 2020, 7:35:30 PM3/14/20
to golang-nuts
I am looking for answer to this SO overflow question:


In essence, I am wondering how to send the response, and *not* invoke any of the subsequent middleware that is declared as part of the chain for that matching request.
There is a boolean flag on http.Response called http.Response.Close.

It's possible that martini reads from http.Response.Close to see if it should invoke the remaining middleware or not, but if so that seems like an imperfect practice/methodology.

-alex

Benjamin

unread,
Mar 14, 2020, 9:39:43 PM3/14/20
to al...@oresoftware.com, golang-nuts
I don’t need to read the stackoverflow. And I don’t know martini.
Middlewares and Handler are all can break the pipeline of http request.
If martini is not designed like this, it is not well designed. Maybe the authors of martini do not have real production software expriences.
Big companies like google likes employing famous university graduated students.
I find even some famous researchers still like students. Event in the go team.
They have graduated from famous university for many years, but still think and do like students. 
Go programming language should be maintained  by engineers not scientists or researchers.


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/b0dbef78-8d0a-49c7-8feb-b3f96ef377ea%40googlegroups.com.

Dan Kortschak

unread,
Mar 14, 2020, 10:05:07 PM3/14/20
to al...@oresoftware.com, golang-nuts
Note that Martini is not maintained anymore and the original author had
a fair bit to say about the merits or otherwise of the packages (via
the wayback machine since codegangsta.io is no longer live):


https://web.archive.org/web/20160518054801/https://codegangsta.io/blog/2014/05/19/my-thoughts-on-martini/

Ian Lance Taylor

unread,
Mar 15, 2020, 2:35:57 AM3/15/20
to Benjamin, al...@oresoftware.com, golang-nuts
On Sat, Mar 14, 2020 at 6:39 PM 'Benjamin' via golang-nuts
<golan...@googlegroups.com> wrote:
>
> I don’t need to read the stackoverflow. And I don’t know martini.
> Middlewares and Handler are all can break the pipeline of http request.
> If martini is not designed like this, it is not well designed. Maybe the authors of martini do not have real production software expriences.
> Big companies like google likes employing famous university graduated students.
> I find even some famous researchers still like students. Event in the go team.
> They have graduated from famous university for many years, but still think and do like students.
> Go programming language should be maintained by engineers not scientists or researchers.

Please be charitable. When people ask for help, please try to help if
you can. Please follow the code of conduct, which you can read at
https://golang.org/conduct. Thanks.

(Note that Martini was not written or maintained by the Go team.)

Ian


> On Mar 15, 2020, at 06:18, al...@oresoftware.com wrote:
>
> I am looking for answer to this SO overflow question:
>
> https://stackoverflow.com/questions/60679922/how-to-break-out-of-martini-middleware
>
> In essence, I am wondering how to send the response, and *not* invoke any of the subsequent middleware that is declared as part of the chain for that matching request.
> There is a boolean flag on http.Response called http.Response.Close.
>
> It's possible that martini reads from http.Response.Close to see if it should invoke the remaining middleware or not, but if so that seems like an imperfect practice/methodology.
>
> -alex
>
> --
> You received this message because you are subscribed to the Google Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/b0dbef78-8d0a-49c7-8feb-b3f96ef377ea%40googlegroups.com.
>
>
> --
> You received this message because you are subscribed to the Google Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/A3BB016C-BAC3-4B95-AB4E-56B4A2D50D58%40icloud.com.

Jake Montgomery

unread,
Mar 15, 2020, 12:10:49 PM3/15/20
to golang-nuts
Note that Martini is not maintained anymore

I hope this is not too off topic, but when choosing a third party go package it is really important to consider whether the package is being maintained. In my experience it is worth steering clear of any complex package that is not being actively maintained, for a variety of reasons. Its usually the second thing I check. A quick glance at https://github.com/go-martini/martini shows that no code changes have been made in the last 4 years and the readme starts with: "NOTE: The martini framework is no longer maintained."

If you do decide to take on such a package be prepared to dive deep into the code, since you will likely have to fix bugs in it, and make features changes yourself when needed. Additionally, it is often difficult to get support, even on SO.

Your question is reasonable, and IMHO posting it here was appropriate. I hope you get an actual answer, but I would not count on it.

 
On Saturday, March 14, 2020 at 10:05:07 PM UTC-4, kortschak wrote:
Note that Martini is not maintained anymore and the original author had
a fair bit to say about the merits or otherwise of the packages (via
the wayback machine since codegangsta.io is no longer live):


https://web.archive.org/web/20160518054801/https://codegangsta.io/blog/2014/05/19/my-thoughts-on-martini/

On Sat, 2020-03-14 at 15:18 -0700, al...@oresoftware.com wrote:
> I am looking for answer to this SO overflow question:
>
>
https://stackoverflow.com/questions/60679922/how-to-break-out-of-martini-middleware
>
> In essence, I am wondering how to send the response, and *not* invoke
> any of the subsequent middleware that is declared as part of the
> chain for that matching request.
> There is a boolean flag on http.Response called http.Response.Close.
>
> It's possible that martini reads from http.Response.Close to see if
> it should invoke the remaining middleware or not, but if so that
> seems like an imperfect practice/methodology.
>
> -alex
> --
> You received this message because you are subscribed to the Google
> Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to golan...@googlegroups.com.

Marcin Romaszewicz

unread,
Mar 15, 2020, 4:14:59 PM3/15/20
to Jake Montgomery, golang-nuts
Martini is defunct, but Gin took their torch and ran with it. I use such http routing frameworks as part of my day job, and would recommend the three following ones.
1) Echo (https://github.com/labstack/echo)
2) Gin (https://github.com/gin-gonic/gin)
3) Chi (https://github.com/go-chi/chi)

I would also pick them in that order of preference. Echo is very similar to Gin, except instead of passing struct pointers around, it uses interfaces which you can mock, and their middleware API is more flexible, precisely allowing to to short circuit the middleware chain wherever you want, it's up to you. Chi is much more minimal.

I'm a big proponent of spec driven development when it comes to HTTP API's, and also have released a package to generate your server boiler plate (works best with Echo) from an OpenAPI v3.0 specification.
https://github.com/deepmap/oapi-codegen


-- Marcin

To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/ae01f686-9b9e-4409-b1ce-6c23d83c7ed3%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages