-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
49 lines (40 loc) · 1.03 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
package main
import (
"fmt"
"net/http"
"runtime"
"github.com/rs/zerolog"
zlog "github.com/rs/zerolog/log"
)
var conf = getConfig()
var routers *routersConf
var log = zlog.Logger
func init() {
routers = getRouters(conf.RoutersFile)
if conf.Debug {
log = log.Level(zerolog.ErrorLevel)
}
log.Info().Bool("debug", conf.Debug).Msg("log init")
}
func main() {
hand := confToRouters(routers.Routers)
go func() {
for {
if e := recover(); e != nil {
buf := make([]byte, 1024*2)
runtime.Stack(buf, true)
log.Error().Interface("err", e).Bytes("body", buf).Msg("error panic")
}
log.Info().Uint32("port", routers.Port).Msg("start router http server")
err := http.ListenAndServe(fmt.Sprintf(":%d", routers.Port), hand)
if err != nil {
log.Error().Err(err).Msg("router http stop")
}
}
}()
log.Info().Uint32("port", conf.Port).Msg("start control http server")
err := http.ListenAndServe(fmt.Sprintf(":%d", conf.Port), controler(hand))
if err != nil {
log.Error().Err(err).Msg("control http stop")
}
}