How to Graceful Restart the iris project ???
How to Graceful Restart the iris project ??? i know how to graceful restart gin project (use endless) but not iris
Hello @weijchun,
Whatever works for gin and net/http works for Iris too.
Take for example, the endless package you mentioned, it wants an http.Handler (mux) on its endless.ListenAndServe("localhost:4242", mux) function.
The app := iris.New() returns an *iris.Application instance, the *iris.Application completes the http.Handler interface and it's ready to use after app.Build(). With Iris, when not calling its .Listen or .Run and want to use it as a simple http.Handler directly, you need to call its "Build" method because there are many features compared to its alternatives that must be built when routing code is finish. Here's an example of your use case:
app := iris.New()
app.Get("/", func(ctx iris.Context) { ctx.Writef("Hello %s", "Iris") }
if err := app.Build(); err!=nil { // <-
panic(err)
}
err := endless.ListenAndServe("localhost:4242", app)
Simple as that! Have fun!