mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 02:17:05 +00:00
add example for #1601
This commit is contained in:
@@ -11,7 +11,7 @@ we use the `iris.Addr` which is an `iris.Runner` type
|
||||
|
||||
```go
|
||||
// Listening on tcp with network address 0.0.0.0:8080
|
||||
// app.Listen(":8080") it's a shortcut of:
|
||||
// app.Listen(":8080") is just a shortcut of:
|
||||
app.Run(iris.Addr(":8080"))
|
||||
```
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ func main() {
|
||||
ctx.HTML("<h1>hi, I just exist in order to see if the server is closed</h1>")
|
||||
})
|
||||
|
||||
idleConnsClosed := make(chan struct{})
|
||||
go func() {
|
||||
ch := make(chan os.Signal, 1)
|
||||
signal.Notify(ch,
|
||||
@@ -37,10 +38,12 @@ func main() {
|
||||
ctx, cancel := stdContext.WithTimeout(stdContext.Background(), timeout)
|
||||
defer cancel()
|
||||
app.Shutdown(ctx)
|
||||
close(idleConnsClosed)
|
||||
}
|
||||
}()
|
||||
|
||||
// Start the server and disable the default interrupt handler in order to
|
||||
// handle it clear and simple by our own, without any issues.
|
||||
app.Listen(":8080", iris.WithoutInterruptHandler)
|
||||
<-idleConnsClosed
|
||||
}
|
||||
|
||||
@@ -17,12 +17,14 @@ import (
|
||||
func main() {
|
||||
app := iris.New()
|
||||
|
||||
idleConnsClosed := make(chan struct{})
|
||||
iris.RegisterOnInterrupt(func() {
|
||||
timeout := 10 * time.Second
|
||||
ctx, cancel := stdContext.WithTimeout(stdContext.Background(), timeout)
|
||||
defer cancel()
|
||||
// close all hosts
|
||||
app.Shutdown(ctx)
|
||||
close(idleConnsClosed)
|
||||
})
|
||||
|
||||
app.Get("/", func(ctx iris.Context) {
|
||||
@@ -30,5 +32,6 @@ func main() {
|
||||
})
|
||||
|
||||
// http://localhost:8080
|
||||
app.Listen(":8080", iris.WithoutInterruptHandler)
|
||||
app.Listen(":8080", iris.WithoutInterruptHandler, iris.WithoutServerError(iris.ErrServerClosed))
|
||||
<-idleConnsClosed
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user