1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-31 16:57:04 +00:00

Update to 7.1.1. Read HISTORY.md

Fix https://github.com/iris-contrib/community-board/issues/11

Read the latest fixes and features by visiting: https://github.com/kataras/iris/blob/master/HISTORY.md


Former-commit-id: 7f35481f917673d0bbb356a4816d9cf54cc0c9ba
This commit is contained in:
kataras
2017-06-13 09:06:10 +03:00
parent 56938636b2
commit a10e80842f
8 changed files with 71 additions and 7 deletions

View File

@@ -12,7 +12,7 @@ import (
// Before continue, please read the below notes:
//
// Current version of Iris is auto-graceful on control+C/command+C
// or whenever host's .Shutdown called.
// or kill command sent or whenever app.Shutdown called.
//
// In order to add a custom interrupt handler(ctrl+c/cmd+c) or
// shutdown manually you have to "schedule a host supervisor's task" or
@@ -29,7 +29,7 @@ func main() {
// tasks are always running in their go-routine by-default.
//
// register custom interrupt handler, fires when ctrl+C/cmd+C pressed.
// register custom interrupt handler, fires when ctrl+C/cmd+C pressed or kill command sent.
app.Scheduler.Schedule(host.OnInterrupt(func(proc host.TaskProcess) {
println("Shutdown the server gracefully...")

View File

@@ -33,7 +33,7 @@ func main() {
// tasks are always running in their go-routine by-default.
//
// register custom interrupt handler, fires when ctrl+C/cmd+C pressed, as we did before.
// register custom interrupt handler, fires when ctrl+C/cmd+C pressed or kill command sent, as we did before.
srv.Schedule(host.OnInterrupt(func(proc host.TaskProcess) {
println("Shutdown the server gracefully...")

View File

@@ -0,0 +1,48 @@
package main
import (
stdContext "context"
"os"
"os/signal"
"syscall"
"time"
"github.com/kataras/iris"
"github.com/kataras/iris/context"
)
func main() {
app := iris.New()
// output startup banner and error logs on os.Stdout
app.Get("/", func(ctx context.Context) {
ctx.HTML(" <h1>hi, I just exist in order to see if the server is closed</h1>")
})
go func() {
ch := make(chan os.Signal, 1)
signal.Notify(ch,
// kill -SIGINT XXXX or Ctrl+c
os.Interrupt,
syscall.SIGINT, // register that too, it should be ok
// os.Kill is equivalent with the syscall.Kill
os.Kill,
syscall.SIGKILL, // register that too, it should be ok
// kill -SIGTERM XXXX
syscall.SIGTERM,
)
select {
case <-ch:
println("Shutdown the server gracefully...")
timeout := 5 * time.Second // give the server 5 seconds to wait for idle connections.
ctx, cancel := stdContext.WithTimeout(stdContext.Background(), timeout)
defer cancel()
app.Shutdown(ctx)
}
}()
// Start the server and disable the default interrupt handler in order to handle it clear and simple by our own, without
// any issues.
app.Run(iris.Addr(":8080"), iris.WithoutInterruptHandler)
}