-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
98 lines (78 loc) · 1.48 KB
/
example_test.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package sigmon_test
import (
"syscall"
"github.com/codemodus/sigmon/v2"
)
func Example() {
sm := sigmon.New(nil)
sm.Start()
// Do things which cannot be affected by OS signals other than SIGKILL...
sm.Set(handle)
// Do things which can be affected by handled OS signals...
sm.Stop()
// OS signals will be handled normally.
}
func Example_elaborated() {
sm := sigmon.New(nil)
sm.Start()
db := newDataBase(creds)
db.Migrate()
app := newWebApp(db)
app.ListenAndServe()
sm.Set(func(s *sigmon.State) {
switch s.Signal() {
case sigmon.SIGHUP:
app.Restart()
default:
app.Shutdown()
}
})
app.Wait()
}
func Example_handlerFunc() {
handle = func(s *sigmon.State) {
switch s.Signal() {
case sigmon.SIGHUP:
server.Restart()
default:
server.Shutdown()
}
}
}
func Example_handlerFuncSyscall() {
handle = func(s *sigmon.State) {
switch syscall.Signal(s.Signal()) {
case syscall.SIGHUP:
server.Restart()
default:
server.Shutdown()
}
}
}
type dataBase struct {
Migrate func()
}
func newDataBase(string) *dataBase {
return &dataBase{
Migrate: func() {},
}
}
type webApp struct {
ListenAndServe func()
Restart func()
Shutdown func()
Wait func()
}
func newWebApp(db *dataBase) *webApp {
return &webApp{
ListenAndServe: func() {},
Restart: func() {},
Shutdown: func() {},
Wait: func() {},
}
}
var (
creds = ""
server = newWebApp(nil)
handle sigmon.HandlerFunc = func(*sigmon.State) {}
)