Skip to content

Commit a59999a

Browse files
committed
PreShutdown hook added.
1 parent 923bb5d commit a59999a

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

app.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@ var (
2727

2828
// App specifies functions to control passed HTTP servers.
2929
type App struct {
30-
// PreServeFn is a common hook notifies client that all servers are
30+
// PreServeFn is a common hook which notifies client that all servers are
3131
// about to start serving.
3232
PreServeFn func(inherited bool) error
3333

34+
// PreShutdownFn is a common hook which notifies client that all servers are
35+
// about to start shutting down.
36+
PreShutdownFn func()
37+
3438
// CompleteShutdownFn is a parent's hook, a part of shutdown process
3539
// that allows client to do extra work after all http servers will
3640
// be shutdown. All dependent resources can be closed here.
@@ -57,6 +61,7 @@ type App struct {
5761
func NewApp(servers ...*http.Server) *App {
5862
a := &App{
5963
PreServeFn: func(inherited bool) error { return nil },
64+
PreShutdownFn: func() {},
6065
CompleteShutdownFn: func() {},
6166
PreParentExitFn: func() {},
6267
servers: servers,
@@ -113,6 +118,7 @@ func (a *App) Shutdown() {
113118
}
114119

115120
logger.Printf("shutdown servers...")
121+
a.PreShutdownFn()
116122
a.served.Wait()
117123

118124
var wg sync.WaitGroup

app_windows.go

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
// App specifies functions to control passed HTTP servers.
1818
type App struct {
1919
PreServeFn func(inherited bool) error
20+
PreShutdownFn func()
2021
CompleteShutdownFn func()
2122
PreParentExitFn func()
2223
servers []*http.Server

0 commit comments

Comments
 (0)