FAQ
Hey,

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:*
https://blog.golang.org/context

*returning an error in a handler:*
https://blog.golang.org/error-handling-and-go
https://www.youtube.com/watch?v=8D3Vmm1BGoY

... 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
Discussion Overview
groupgolang-nuts @
categoriesgo
postedFeb 17, '16 at 2:09a
activeFeb 17, '16 at 2:09a
posts1
users1
websitegolang.org

1 user in discussion

Nick Stogner: 1 post

People

Translate

site design / logo © 2021 Grokbase