-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
executable file
·65 lines (54 loc) · 1.47 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
// Code generated by hertz generator.
package main
import (
"github.com/cloudwego/hertz/pkg/app/middlewares/server/recovery"
"github.com/cloudwego/hertz/pkg/app/server"
"github.com/cloudwego/hertz/pkg/common/hlog"
"github.com/hertz-contrib/cors"
"github.com/hertz-contrib/gzip"
"github.com/hertz-contrib/logger/accesslog"
hertzlogrus "github.com/hertz-contrib/logger/logrus"
"github.com/hertz-contrib/pprof"
"github.com/li-jin-gou/hz_demo/biz/router"
"github.com/li-jin-gou/hz_demo/conf"
"gopkg.in/natefinch/lumberjack.v2"
)
func main() {
// init dal
// dal.Init()
address := conf.GetConf().Hertz.Address
h := server.New(server.WithHostPorts(address))
router.GeneratedRegister(h)
// do what you wanted
// add some render data: <no value>
registerMiddleware(h)
h.Spin()
}
func registerMiddleware(h *server.Hertz) {
// pprof
if conf.GetConf().Hertz.EnablePprof {
pprof.Register(h)
}
// gzip
if conf.GetConf().Hertz.EnableGzip {
h.Use(gzip.Gzip(gzip.DefaultCompression))
}
// access log
if conf.GetConf().Hertz.EnableAccessLog {
h.Use(accesslog.New())
}
// log
logger := hertzlogrus.NewLogger()
hlog.SetLogger(logger)
hlog.SetLevel(conf.LogLevel())
hlog.SetOutput(&lumberjack.Logger{
Filename: conf.GetConf().Hertz.LogFileName,
MaxSize: conf.GetConf().Hertz.LogMaxSize,
MaxBackups: conf.GetConf().Hertz.LogMaxBackups,
MaxAge: conf.GetConf().Hertz.LogMaxAge,
})
// recovery
h.Use(recovery.Recovery())
// cores
h.Use(cors.Default())
}