File tree 1 file changed +17
-0
lines changed
1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,9 @@ package vproxy
3
3
import (
4
4
"fmt"
5
5
"net/http"
6
+ "os"
7
+ "os/signal"
8
+ "syscall"
6
9
)
7
10
8
11
// StartHello world service on the given host/port
@@ -11,6 +14,20 @@ import (
11
14
// It's mainly here to serve as a simple demo of vproxy's abilities (see readme).
12
15
func StartHello (host string , port int ) error {
13
16
fmt .Printf ("~> starting vproxy hello service at http://%s:%d\n " , host , port )
17
+
18
+ // trap signals so we can print before exiting
19
+ c := make (chan os.Signal , 1 )
20
+ signal .Notify (c , os .Interrupt , syscall .SIGTERM , syscall .SIGHUP )
21
+ go func () {
22
+ // catch ^c, cleanup
23
+ s := <- c
24
+ if s == nil {
25
+ return
26
+ }
27
+ fmt .Println ("~> caught signal:" , s )
28
+ os .Exit (0 )
29
+ }()
30
+
14
31
return http .ListenAndServe (fmt .Sprintf ("%s:%d" , host , port ), http .HandlerFunc (helloHandler ))
15
32
}
16
33
You can’t perform that action at this time.
0 commit comments