Skip to content

how to break-out of middleware chain using Martini #428

@ORESoftware

Description

@ORESoftware

I put this question on SO and am looking for answers - this question may be based off a false assumption:

https://stackoverflow.com/questions/60679922/how-to-break-out-of-martini-middleware

but at the very least I have no idea how martini would know when to keep invoking the middleware chain and when not to? it wouldn't know even if you aleady set the http status code or wrote the response body, you may still want to keep writing in subsequent middleware funcs. someone please explain how to return early out of the chain.

Perhaps this is the best way to do it?

m.Use(func(c martini.Context, w http.ResponseWriter){

    if reqIsMalformed() {
        http.Error(w, "Bad request because xyz", 422)
        return;
    }

    c.Next()  // only invoke remaining middleware if the request is valid?

})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions