-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
executable file
·70 lines (62 loc) · 1.41 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
// Code generated by hertz generator.
package main
import (
"context"
"xzdp/biz/dal/mysql"
"xzdp/biz/dal/redis"
"xzdp/biz/middleware/interceptor"
"xzdp/conf"
"net/http"
_ "net/http/pprof" // 导入 pprof HTTP handler
"github.com/cloudwego/hertz/pkg/app"
"github.com/cloudwego/hertz/pkg/app/server"
"github.com/cloudwego/hertz/pkg/common/hlog"
)
func main() {
go func() {
_ = http.ListenAndServe(":6060", nil)
}()
h := server.Default(server.WithHostPorts(conf.GetConf().Hertz.Address))
h.Use(interceptor.CheckToken)
h.Use(interceptor.Cors)
excludedPaths := []string{
"/shop",
"/voucher",
"/shop-type",
"/upload",
"/blog/hot",
"/user/code",
"/user/login",
"/follow",
"/imgs",
"/message",
"/blog",
}
// excludedPaths := map[string]bool{
// "/shop": true,
// "/voucher": true,
// "/shop-type/list": true,
// "/upload": true,
// "/blog/hot": true,
// "/user/code": true,
// "/user/login": true,
// }
h.Use(func(ctx context.Context, c *app.RequestContext) {
path := string(c.Request.Path())
for i := 0; i < len(excludedPaths); i++ {
if len(path) < len(excludedPaths[i]) {
continue
}
if path[:len(excludedPaths[i])] == excludedPaths[i] {
return
}
}
hlog.CtxInfof(ctx, "path = %s", path)
interceptor.LoginInterceptor(ctx, c)
})
mysql.Init()
redis.Init()
h.Use(interceptor.UniqueVisitor)
register(h)
h.Spin()
}