-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.go
63 lines (52 loc) · 1.21 KB
/
server.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
package main
import (
"github.com/webitel/engine/apis"
"github.com/webitel/engine/app"
"github.com/webitel/engine/grpc_api"
"github.com/webitel/engine/wsapi"
"github.com/webitel/wlog"
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
"syscall"
)
func main() {
interruptChan := make(chan os.Signal, 1)
a, err := app.New()
if err != nil {
wlog.Critical("failed to start", wlog.Err(err))
return
}
defer a.Shutdown()
serverErr := a.StartServer()
if serverErr != nil {
wlog.Critical(serverErr.Error())
return
}
wsapi.Init(a, a.Srv.WebSocketRouter)
apis.Init(a, a.Srv.Router)
grpc_api.Init(a, a.GrpcServer.Server())
if err := a.StartGrpcServer(); err != nil {
panic(err.Error())
}
var dbg *http.Server
if a.Config().Dev {
dbg = setDebug()
}
signal.Notify(interruptChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
<-interruptChan
if dbg != nil {
dbg.Close()
}
}
func setDebug() *http.Server {
//debug.SetGCPercent(-1)
server := &http.Server{Addr: ":8091", Handler: nil}
go func(s *http.Server) {
wlog.Info("start debug server on http://localhost:8091/debug/pprof/")
s.ListenAndServe()
wlog.Info("stop debug server on http://localhost:8091/debug/pprof/")
}(server)
return server
}