Skip to content

Commit

Permalink
Document the posibility to reuse a chain. Fixes justinas#3.
Browse files Browse the repository at this point in the history
  • Loading branch information
justinas committed Jun 6, 2014
1 parent 94d6150 commit 32c45f9
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ func New(constructors ...Constructor) Chain {
// and finally, the given handler
// (assuming every middleware calls the following one).
//
// A chain can be safely reused by calling Then() several times.
// stdStack := alice.New(ratelimitHandler, csrfHandler)
// indexPipe = stdStack.Then(indexHandler)
// authPipe = stdStack.Then(authHandler)
// Note that constructors are called on every call to Then()
// and thus several instances of the same middleware will be created
// when a chain is reused in this way.
// For proper middleware, this should cause no problems.
//
// Then() treats nil as http.DefaultServeMux.
func (c Chain) Then(h http.Handler) http.Handler {
var final http.Handler
Expand Down

0 comments on commit 32c45f9

Please sign in to comment.