diff options
author | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2020-01-12 16:40:01 +0300 |
---|---|---|
committer | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2020-01-12 16:40:01 +0300 |
commit | 837cfe3223db11bf7f5edb6ba738d3e328b80ea2 (patch) | |
tree | 8207e53a6411ea5cd9f1da96f0de9d957c7301f2 /example/http_server.go | |
parent | 01eeeaf5e136928abe75f95d58f3f9cce11c6fe6 (diff) |
Refactored
New clean API
Timeouts and restart limits
Diffstat (limited to 'example/http_server.go')
-rwxr-xr-x | example/http_server.go | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/example/http_server.go b/example/http_server.go index fe1d456..6bb7157 100755 --- a/example/http_server.go +++ b/example/http_server.go @@ -13,7 +13,7 @@ import ( func main() { // New instance with builtin context - r := rutina.New(rutina.WithStdLogger()) + r := rutina.New(rutina.Opt.SetListenOsSignals(true)) srv := &http.Server{Addr: ":8080"} http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { @@ -27,17 +27,14 @@ func main() { } log.Println("Server stopped") return nil - }) + }, rutina.RunOpt.SetOnDone(rutina.Shutdown)) - // Gracefully stoping server when context canceled + // Gracefully stopping server when context canceled r.Go(func(ctx context.Context) error { <-ctx.Done() log.Println("Stopping server...") return srv.Shutdown(ctx) - }) - - // OS signals subscriber - r.ListenOsSignals() + }, nil) if err := r.Wait(); err != nil { log.Fatal(err) |