1 Star 2 Fork 0

api-go / iris

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.go 883 Bytes
一键复制 编辑 原始数据 按行查看 历史
package main
import (
stdContext "context"
"time"
"github.com/kataras/iris"
)
// Before continue:
//
// Gracefully Shutdown on control+C/command+C or when kill command sent is ENABLED BY-DEFAULT.
//
// In order to manually manage what to do when app is interrupted,
// We have to disable the default behavior with the option `WithoutInterruptHandler`
// and register a new interrupt handler (globally, across all possible hosts).
func main() {
app := iris.New()
iris.RegisterOnInterrupt(func() {
timeout := 5 * time.Second
ctx, cancel := stdContext.WithTimeout(stdContext.Background(), timeout)
defer cancel()
// close all hosts
app.Shutdown(ctx)
})
app.Get("/", func(ctx iris.Context) {
ctx.HTML(" <h1>hi, I just exist in order to see if the server is closed</h1>")
})
// http://localhost:8080
app.Run(iris.Addr(":8080"), iris.WithoutInterruptHandler)
}
1
https://gitee.com/netscript/iris.git
git@gitee.com:netscript/iris.git
netscript
iris
iris
v11.1.1

搜索帮助