forked from andeya/faygo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
83 lines (72 loc) · 1.75 KB
/
main.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
package main
import (
"net/http"
_ "net/http/pprof"
"time"
"github.com/henrylee2cn/faygo"
"github.com/henrylee2cn/faygo/samples/demo/router"
)
// Browse 'http://localhost:8080/apidoc' and 'http://localhost:8081/apidoc' to test.
// run type 1
func main() {
// pprof
// http://localhost:7777/debug/pprof
go pprofServer()
faygo.SetShutdown(time.Minute, func() error {
faygo.Debug("Before services are closing1: wait for 1s...")
time.Sleep(1 * time.Second)
faygo.Debug("Before services are closed1!")
return nil
}, func() error {
faygo.Debug("After services are closing2: wait for 1s...")
time.Sleep(1 * time.Second)
faygo.Debug("After services are closed2!")
return nil
})
faygo.SetUpload("./upload/0", false, false)
// faygo.SetStatic("./static", false, false)
{
app1 := faygo.New("myapp1", "1.0")
router.Route1(app1)
}
{
app2 := faygo.New("myapp2", "1.0")
router.Route2(app2)
}
faygo.Run()
}
// run type 2
func main2() {
// pprof
// http://localhost:7777/debug/pprof
go pprofServer()
faygo.SetShutdown(time.Minute, func() error {
faygo.Debug("Before services are closing1: wait for 1s...")
time.Sleep(1 * time.Second)
faygo.Debug("Before services are closed1!")
return nil
}, func() error {
faygo.Debug("After services are closing2: wait for 1s...")
time.Sleep(1 * time.Second)
faygo.Debug("After services are closed2!")
return nil
})
faygo.SetUpload("./upload/0", false, false)
// faygo.SetStatic("./static", false, false)
{
app1 := faygo.New("myapp1", "1.0")
router.Route1(app1)
go app1.Run()
}
{
app2 := faygo.New("myapp2", "1.0")
router.Route2(app2)
go app2.Run()
}
select {}
}
// only for pprof
// http://localhost:7777/debug/pprof
func pprofServer() {
http.ListenAndServe("0.0.0.0:7777", nil)
}