I just uploaded my http middleware repository (httpware
<https://github.com/nstogner/httpware>) to github. I am looking for early
feedback before trying to progress towards a stable release.

The repository contains various middleware packages with the following
handler function:
ServeHTTPContext(context.Context, http.ResponseWriter, *http.Request) error
This form was mainly influenced by the following:

*net/context for handler data-sharing:*

*returning an error in a handler:*

... My thinking is that error handling via return values allows for
standardizing error response across various middleware. It also prevents
the pitfall of forgetting to return early after a call to http.Error as is
easy to do within a standard http.Handler.

The included middleware implements the httpware.Middleware interface which
allows for a chaining function, httpware.MustCompose (similar to alice
<https://github.com/justinas/alice>), to compose them:
type Middleware interface {
     Contains() []string
     Requires() []string
     Handle(Handler) Handler
I arrived at this interface out of a need to have some middleware depend on
other middleware. I wanted to make sure dependencies were met when the
middleware was composed together (hence the Contains() and Requires()
methods). Contains() returns a slice here to allow for composites of
multiple middleware instances to fulfill the Middleware interface.

Let me know your opinion!

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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 1 | next ›
Discussion Overview
groupgolang-nuts @
postedFeb 17, '16 at 2:09a
activeFeb 17, '16 at 2:09a

1 user in discussion

Nick Stogner: 1 post



site design / logo © 2021 Grokbase