1
0
mirror of https://github.com/kataras/iris.git synced 2026-03-06 08:25:59 +00:00

Add iris#ConfigureHost as an alternative way to interact with the app's hosts.

Former-commit-id: 5f36f44b86b70818c4c0c6ef7c178b550cc4ac46
This commit is contained in:
kataras
2017-07-31 19:11:58 +03:00
parent 4f2985cb4e
commit 8dc4779ef5
8 changed files with 145 additions and 7 deletions

View File

@@ -18,6 +18,64 @@ Developers are not forced to upgrade if they don't really need it. Upgrade whene
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
# Mo, 31 July 2017 | v8.1.2
Add a `ConfigureHost` function as an alternative way to customize the hosts via `host.Configurator`.
The first way was to pass `host.Configurator` as optional arguments on `iris.Runner`s built'n functions (`iris#Server, iris#Listener, iris#Addr, iris#TLS, iris#AutoTLS`), example of this can be found [there](https://github.com/kataras/iris/blob/master/_examples/http-listening/notify-on-shutdown).
Example Code:
```go
package main
import (
stdContext "context"
"time"
"github.com/kataras/iris"
"github.com/kataras/iris/context"
"github.com/kataras/iris/core/host"
)
func main() {
app := iris.New()
app.Get("/", func(ctx context.Context) {
ctx.HTML("<h1>Hello, try to refresh the page after ~10 secs</h1>")
})
app.ConfigureHost(configureHost) // or pass "configureHost" as `app.Addr` argument, same result.
app.Logger().Info("Wait 10 seconds and check your terminal again")
// simulate a shutdown action here...
go func() {
<-time.After(10 * time.Second)
timeout := 5 * time.Second
ctx, cancel := stdContext.WithTimeout(stdContext.Background(), timeout)
defer cancel()
// close all hosts, this will notify the callback we had register
// inside the `configureHost` func.
app.Shutdown(ctx)
}()
// http://localhost:8080
// wait 10 seconds and check your terminal.
app.Run(iris.Addr(":8080"), iris.WithoutServerError(iris.ErrServerClosed))
}
func configureHost(su *host.Supervisor) {
// here we have full access to the host that will be created
// inside the `app.Run` or `app.NewHost` function .
//
// we're registering a shutdown "event" callback here:
su.RegisterOnShutdown(func() {
println("server is closed")
})
// su.RegisterOnError
// su.RegisterOnServe
}
```
# Su, 30 July 2017
Greetings my friends, nothing special today, no version number yet.