aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorAlexander Kiryukhin <alexander@kiryukhin.su>2019-01-17 07:54:39 +0300
committerAlexander Kiryukhin <alexander@kiryukhin.su>2019-01-17 07:54:39 +0300
commitc5776ba6a3d8303650208ee8abc8f63cadf5127a (patch)
treecf92f3d64a46f7167b9857688e5344554b2a8d69 /example
parentd64ca3bd06c6a2c702f3604d95658566907a9beb (diff)
Many changesv0.2.0
Diffstat (limited to 'example')
-rwxr-xr-x[-rw-r--r--]example/http_server.go21
1 files changed, 4 insertions, 17 deletions
diff --git a/example/http_server.go b/example/http_server.go
index a8072bb..ef25567 100644..100755
--- a/example/http_server.go
+++ b/example/http_server.go
@@ -4,19 +4,15 @@ package main
import (
"context"
+ "github.com/neonxp/rutina"
"io"
"log"
"net/http"
- "os"
- "os/signal"
- "syscall"
-
- "github.com/neonxp/rutina"
)
func main() {
- // New instance with builtin context. Alternative: r, ctx := rutina.WithContext(ctx)
- r, _ := rutina.New()
+ // New instance with builtin context. Alternative: r, ctx := rutina.OptionContext(ctx)
+ r, _ := rutina.New(rutina.WithStdLogger())
srv := &http.Server{Addr: ":8080"}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
@@ -40,16 +36,7 @@ func main() {
})
// OS signals subscriber
- r.Go(func(ctx context.Context) error {
- sig := make(chan os.Signal, 1)
- signal.Notify(sig, syscall.SIGTERM, syscall.SIGINT)
- select {
- case <-sig:
- log.Println("TERM or INT signal received")
- case <-ctx.Done():
- }
- return nil
- })
+ r.ListenOsSignals()
if err := r.Wait(); err != nil {
log.Fatal(err)