1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-23 04:47:02 +00:00

Catch os.Interrupt signal with iris.PostInterrupt example added in comments.

https://github.com/iris-contrib/examples/tree/master/os_interrupt
This commit is contained in:
Gerasimos (Makis) Maropoulos
2017-01-11 18:01:29 +02:00
parent 5ad7c6e01f
commit 23f9ad13a1
3 changed files with 16 additions and 0 deletions

View File

@@ -96,11 +96,13 @@ type (
// graceful shutdown can be done here
//
// Read more here: https://github.com/kataras/iris/blob/master/HISTORY.md#608---609
// Example: https://github.com/iris-contrib/examples/tree/master/os_interrupt
PostInterrupt(*Framework)
}
// PostInterruptFunc implements the simple function listener for the PostInterrupt(*Framework)
//
// Read more here: https://github.com/kataras/iris/blob/master/HISTORY.md#608---609
// Example: https://github.com/iris-contrib/examples/tree/master/os_interrupt
PostInterruptFunc func(*Framework)
// pluginPreClose implements the PreClose(*Framework) method
@@ -220,6 +222,15 @@ func (fn PostListenFunc) PostListen(station *Framework) {
fn(station)
}
// PostInterrupt it's being called only one time, when os.Interrupt system event catched
// graceful shutdown can be done here
//
// Read more here: https://github.com/kataras/iris/blob/master/HISTORY.md#608---609
// Example: https://github.com/iris-contrib/examples/tree/master/os_interrupt
func (fn PostInterruptFunc) PostInterrupt(station *Framework) {
fn(station)
}
// PreClose it's being called only one time, BEFORE the Iris .Close method
// any plugin cleanup/clear memory happens here
//
@@ -540,6 +551,7 @@ func (p *pluginContainer) PostListenFired() bool {
// PostInterrupt adds a PostInterrupt plugin-function to the plugin flow container
//
// Read more here: https://github.com/kataras/iris/blob/master/HISTORY.md#608---609
// Example: https://github.com/iris-contrib/examples/tree/master/os_interrupt
func (p *pluginContainer) PostInterrupt(fn PostInterruptFunc) {
p.Add(fn)
}