diff --git a/app.go b/app.go index 38e35d9d56..2ffd4e808b 100644 --- a/app.go +++ b/app.go @@ -798,6 +798,11 @@ func (app *App) Stack() [][]*Route { return app.stack } +// HandlersCount returns the amount of registered handlers. +func (app *App) HandlersCount() uint32 { + return app.handlerCount +} + // Shutdown gracefully shuts down the server without interrupting any active connections. // Shutdown works by first closing all open listeners and then waiting indefinitely for all connections to return to idle and then shut down. // diff --git a/app_test.go b/app_test.go index 748551ea2e..fb6cafb06f 100644 --- a/app_test.go +++ b/app_test.go @@ -1250,6 +1250,18 @@ func Test_App_Stack(t *testing.T) { utils.AssertEqual(t, 1, len(stack[methodInt(MethodTrace)])) } +// go test -run Test_App_HandlersCount +func Test_App_HandlersCount(t *testing.T) { + app := New() + + app.Use("/path0", testEmptyHandler) + app.Get("/path2", testEmptyHandler) + app.Post("/path3", testEmptyHandler) + + count := app.HandlersCount() + utils.AssertEqual(t, uint32(4), count) +} + // go test -run Test_App_ReadTimeout func Test_App_ReadTimeout(t *testing.T) { app := New(Config{