Skip to content

Commit

Permalink
Allow passing nil to ThenFunc
Browse files Browse the repository at this point in the history
  • Loading branch information
justinas committed Jul 20, 2014
1 parent 4623c37 commit 35b4790
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ func (c Chain) Then(h http.Handler) http.Handler {
//
// ThenFunc provides all the guarantees of Then.
func (c Chain) ThenFunc(fn http.HandlerFunc) http.Handler {
if fn == nil {
return c.Then(nil)
}
return c.Then(http.HandlerFunc(fn))
}

Expand Down
5 changes: 5 additions & 0 deletions chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ func TestThenTreatsNilAsDefaultServeMux(t *testing.T) {
assert.Equal(t, chained, http.DefaultServeMux)
}

func TestThenFuncTreatsNilAsDefaultServeMux(t *testing.T) {
chained := New().ThenFunc(nil)
assert.Equal(t, chained, http.DefaultServeMux)
}

func TestThenOrdersHandlersRight(t *testing.T) {
t1 := tagMiddleware("t1\n")
t2 := tagMiddleware("t2\n")
Expand Down

0 comments on commit 35b4790

Please sign in to comment.