-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
doc.go
43 lines (34 loc) · 749 Bytes
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
Package shutdown provides simple shutdown signals handler with callback
package main
import (
"context"
"net/http"
"os"
"time"
"log"
"github.com/vardius/shutdown"
)
func main() {
ctx := context.Background()
http.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
io.WriteString(w, "Hello!\n")
})
stop := func() {
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
log.Printf("shutting down...\n")
if err := srv.Shutdown(ctx); err != nil {
log.Printf("shutdown error: %v\n", err)
} else {
log.Printf("gracefully stopped\n")
}
}
go func() {
log.Printf("%v\n", http.ListenAndServe(":8080", nil))
stop()
os.Exit(1)
}()
}
*/
package shutdown