Allow passing nil to ThenFunc
diff --git a/chain.go b/chain.go
index 97b1c6d..9b04887 100644
--- a/chain.go
+++ b/chain.go
@@ -69,6 +69,9 @@
//
// 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))
}
diff --git a/chain_test.go b/chain_test.go
index d78b1d9..e2bf501 100644
--- a/chain_test.go
+++ b/chain_test.go
@@ -55,6 +55,11 @@
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")