summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go16
1 files changed, 15 insertions, 1 deletions
diff --git a/main.go b/main.go
index a595ab1..cacd01c 100644
--- a/main.go
+++ b/main.go
@@ -3,6 +3,9 @@ package main
import (
"fmt"
"log"
+ "os"
+ "os/signal"
+ "syscall"
"net/http"
"time"
@@ -34,9 +37,20 @@ func run() {
ReadTimeout: ReadTimeout,
}
- log.Fatal(srv.ListenAndServe())
+ go srv.ListenAndServe()
+
+ await(syscall.SIGTERM, syscall.SIGINT)
}
func hello(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Hello world!")
}
+
+func await(signals ...syscall.Signal) {
+ listener := make(chan os.Signal, 1)
+ for _, s := range signals {
+ signal.Notify(listener, s)
+ }
+ sig := <-listener
+ log.Printf("Received OS signal '%v'\n", sig)
+}