Skip to content

Commit

Permalink
Add method the get registered handler count. (#1672)
Browse files Browse the repository at this point in the history
  • Loading branch information
efectn committed Dec 29, 2021
1 parent 59e4bf6 commit fbee8fb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app.go
Expand Up @@ -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.
//
Expand Down
12 changes: 12 additions & 0 deletions app_test.go
Expand Up @@ -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{
Expand Down

0 comments on commit fbee8fb

Please sign in to comment.