正在显示
16 个修改的文件
包含
372 行增加
和
111 行删除
@@ -6,6 +6,8 @@ ARG PROJECT=core | @@ -6,6 +6,8 @@ ARG PROJECT=core | ||
6 | WORKDIR /build | 6 | WORKDIR /build |
7 | COPY . . | 7 | COPY . . |
8 | 8 | ||
9 | +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories | ||
10 | +RUN apk update --no-cache && apk add --no-cache tzdata | ||
9 | RUN go env -w GO111MODULE=on \ | 11 | RUN go env -w GO111MODULE=on \ |
10 | && go env -w GOPROXY=https://goproxy.cn,direct \ | 12 | && go env -w GOPROXY=https://goproxy.cn,direct \ |
11 | && go env -w CGO_ENABLED=0 \ | 13 | && go env -w CGO_ENABLED=0 \ |
@@ -28,7 +30,9 @@ LABEL org.opencontainers.image.authors=${AUTHOR} | @@ -28,7 +30,9 @@ LABEL org.opencontainers.image.authors=${AUTHOR} | ||
28 | WORKDIR /app | 30 | WORKDIR /app |
29 | ENV PROJECT=${PROJECT} | 31 | ENV PROJECT=${PROJECT} |
30 | ENV CONFIG_FILE=${CONFIG_FILE} | 32 | ENV CONFIG_FILE=${CONFIG_FILE} |
33 | +ENV TZ Asia/Shanghai | ||
31 | 34 | ||
35 | +COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /usr/share/zoneinfo/Asia/Shanghai | ||
32 | COPY --from=builder /build/api/${PROJECT} ./ | 36 | COPY --from=builder /build/api/${PROJECT} ./ |
33 | COPY --from=builder /build/cmd/chart-server/api/etc/${CONFIG_FILE} ./etc/ | 37 | COPY --from=builder /build/cmd/chart-server/api/etc/${CONFIG_FILE} ./etc/ |
34 | COPY --from=builder /build/cmd/chart-server/api/public ./public/ | 38 | COPY --from=builder /build/cmd/chart-server/api/public ./public/ |
@@ -5,7 +5,8 @@ ARG PROJECT=core | @@ -5,7 +5,8 @@ ARG PROJECT=core | ||
5 | 5 | ||
6 | WORKDIR /build | 6 | WORKDIR /build |
7 | COPY . . | 7 | COPY . . |
8 | - | 8 | +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories |
9 | +RUN apk update --no-cache && apk add --no-cache tzdata | ||
9 | RUN go env -w GO111MODULE=on \ | 10 | RUN go env -w GO111MODULE=on \ |
10 | && go env -w GOPROXY=https://goproxy.cn,direct \ | 11 | && go env -w GOPROXY=https://goproxy.cn,direct \ |
11 | && go env -w CGO_ENABLED=0 \ | 12 | && go env -w CGO_ENABLED=0 \ |
@@ -28,7 +29,9 @@ LABEL org.opencontainers.image.authors=${AUTHOR} | @@ -28,7 +29,9 @@ LABEL org.opencontainers.image.authors=${AUTHOR} | ||
28 | WORKDIR /app | 29 | WORKDIR /app |
29 | ENV PROJECT=${PROJECT} | 30 | ENV PROJECT=${PROJECT} |
30 | ENV CONFIG_FILE=${CONFIG_FILE} | 31 | ENV CONFIG_FILE=${CONFIG_FILE} |
32 | +ENV TZ Asia/Shanghai | ||
31 | 33 | ||
34 | +COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /usr/share/zoneinfo/Asia/Shanghai | ||
32 | COPY --from=builder /build/api/${PROJECT} ./ | 35 | COPY --from=builder /build/api/${PROJECT} ./ |
33 | COPY --from=builder /build/cmd/chart-server/api/etc/${CONFIG_FILE} ./etc/ | 36 | COPY --from=builder /build/cmd/chart-server/api/etc/${CONFIG_FILE} ./etc/ |
34 | COPY --from=builder /build/cmd/chart-server/api/public ./public/ | 37 | COPY --from=builder /build/cmd/chart-server/api/public ./public/ |
1 | Name: chart | 1 | Name: chart |
2 | Host: 0.0.0.0 | 2 | Host: 0.0.0.0 |
3 | Port: 8080 | 3 | Port: 8080 |
4 | -Verbose: true | 4 | +Verbose: false |
5 | HostName: http://sumifcc-bchart-dev.sumifcc.com | 5 | HostName: http://sumifcc-bchart-dev.sumifcc.com |
6 | Timeout: 30000 | 6 | Timeout: 30000 |
7 | +LogRequest: true # 记录详细请求日志 | ||
7 | 8 | ||
8 | Log: | 9 | Log: |
9 | Mode: file | 10 | Mode: file |
@@ -15,6 +16,11 @@ JwtAuth: | @@ -15,6 +16,11 @@ JwtAuth: | ||
15 | AccessSecret: digital-platform | 16 | AccessSecret: digital-platform |
16 | Expire: 360000 | 17 | Expire: 360000 |
17 | 18 | ||
19 | +ApiAuth: | ||
20 | + Name: ApiAuth | ||
21 | + Host: http://digital-platform-dev.fjmaimaimai.com | ||
22 | + Timeout: 0s | ||
23 | + | ||
18 | Redis: | 24 | Redis: |
19 | Host: 192.168.0.243:6379 | 25 | Host: 192.168.0.243:6379 |
20 | Type: node | 26 | Type: node |
@@ -3,6 +3,7 @@ Host: 0.0.0.0 | @@ -3,6 +3,7 @@ Host: 0.0.0.0 | ||
3 | Port: 8080 | 3 | Port: 8080 |
4 | Verbose: false | 4 | Verbose: false |
5 | HostName: http://sumifcc-bchart.sumifcc.com | 5 | HostName: http://sumifcc-bchart.sumifcc.com |
6 | +LogRequest: true # 记录详细请求日志 | ||
6 | 7 | ||
7 | Log: | 8 | Log: |
8 | Mode: file | 9 | Mode: file |
@@ -13,6 +14,11 @@ JwtAuth: | @@ -13,6 +14,11 @@ JwtAuth: | ||
13 | AccessSecret: digital-platform | 14 | AccessSecret: digital-platform |
14 | Expire: 360000 | 15 | Expire: 360000 |
15 | 16 | ||
17 | +ApiAuth: | ||
18 | + Name: ApiAuth | ||
19 | + Host: https://digital-platform.sumifcc.com | ||
20 | + Timeout: 0s | ||
21 | + | ||
16 | Redis: | 22 | Redis: |
17 | Host: 192.168.0.243:6379 | 23 | Host: 192.168.0.243:6379 |
18 | Type: node | 24 | Type: node |
1 | Name: chart | 1 | Name: chart |
2 | Host: 0.0.0.0 | 2 | Host: 0.0.0.0 |
3 | Port: 8081 | 3 | Port: 8081 |
4 | -Verbose: true | 4 | +Verbose: false |
5 | HostName: http://sumifcc-bchart-dev.sumifcc.com | 5 | HostName: http://sumifcc-bchart-dev.sumifcc.com |
6 | Timeout: 30000 | 6 | Timeout: 30000 |
7 | +LogRequest: true # 记录详细请求日志 | ||
7 | 8 | ||
8 | Log: | 9 | Log: |
9 | - #Mode: file | 10 | + Mode: file |
10 | Encoding: plain | 11 | Encoding: plain |
11 | Level: debug # info | 12 | Level: debug # info |
12 | MaxSize: 1 # 2MB | 13 | MaxSize: 1 # 2MB |
@@ -17,6 +18,11 @@ JwtAuth: | @@ -17,6 +18,11 @@ JwtAuth: | ||
17 | AccessSecret: digital-platform | 18 | AccessSecret: digital-platform |
18 | Expire: 360000 | 19 | Expire: 360000 |
19 | 20 | ||
21 | +ApiAuth: | ||
22 | + Name: ApiAuth | ||
23 | + Host: http://digital-platform-dev.fjmaimaimai.com | ||
24 | + Timeout: 0s | ||
25 | + | ||
20 | Redis: | 26 | Redis: |
21 | Host: 127.0.0.1:6379 | 27 | Host: 127.0.0.1:6379 |
22 | Type: node | 28 | Type: node |
@@ -13,6 +13,8 @@ type Config struct { | @@ -13,6 +13,8 @@ type Config struct { | ||
13 | config.Config | 13 | config.Config |
14 | Redis redis.RedisConf `json:",optional"` | 14 | Redis redis.RedisConf `json:",optional"` |
15 | ByteMetadata ApiService | 15 | ByteMetadata ApiService |
16 | + ApiAuth ApiService | ||
17 | + LogRequest bool `json:",optional,default=true"` | ||
16 | HostName string // 服务域名 | 18 | HostName string // 服务域名 |
17 | KqConsumerConf kq.KqConf | 19 | KqConsumerConf kq.KqConf |
18 | } | 20 | } |
@@ -16,65 +16,71 @@ import ( | @@ -16,65 +16,71 @@ import ( | ||
16 | 16 | ||
17 | func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | 17 | func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { |
18 | server.AddRoutes( | 18 | server.AddRoutes( |
19 | - []rest.Route{ | ||
20 | - { | ||
21 | - Method: http.MethodPost, | ||
22 | - Path: "/chart", | ||
23 | - Handler: chart.SaveChartHandler(serverCtx), | ||
24 | - }, | ||
25 | - { | ||
26 | - Method: http.MethodPost, | ||
27 | - Path: "/chart/saveas", | ||
28 | - Handler: chart.SaveAsChartHandler(serverCtx), | ||
29 | - }, | ||
30 | - { | ||
31 | - Method: http.MethodDelete, | ||
32 | - Path: "/chart/:id", | ||
33 | - Handler: chart.DeleteChartHandler(serverCtx), | ||
34 | - }, | ||
35 | - { | ||
36 | - Method: http.MethodPut, | ||
37 | - Path: "/chart/:id", | ||
38 | - Handler: chart.UpdateChartHandler(serverCtx), | ||
39 | - }, | ||
40 | - { | ||
41 | - Method: http.MethodPost, | ||
42 | - Path: "/chart/search", | ||
43 | - Handler: chart.SearchChartHandler(serverCtx), | ||
44 | - }, | ||
45 | - { | ||
46 | - Method: http.MethodPost, | ||
47 | - Path: "/chart/move", | ||
48 | - Handler: chart.UpdateChartSortHandler(serverCtx), | ||
49 | - }, | ||
50 | - { | ||
51 | - Method: http.MethodPost, | ||
52 | - Path: "/chart/rename", | ||
53 | - Handler: chart.RenameChartSortHandler(serverCtx), | ||
54 | - }, | ||
55 | - { | ||
56 | - Method: http.MethodPost, | ||
57 | - Path: "/chart/components/search", | ||
58 | - Handler: chart.SearchChartComponentsHandler(serverCtx), | ||
59 | - }, | ||
60 | - }, | 19 | + rest.WithMiddlewares( |
20 | + []rest.Middleware{serverCtx.LoginStatusCheck, serverCtx.LogRequest}, | ||
21 | + []rest.Route{ | ||
22 | + { | ||
23 | + Method: http.MethodPost, | ||
24 | + Path: "/chart", | ||
25 | + Handler: chart.SaveChartHandler(serverCtx), | ||
26 | + }, | ||
27 | + { | ||
28 | + Method: http.MethodPost, | ||
29 | + Path: "/chart/saveas", | ||
30 | + Handler: chart.SaveAsChartHandler(serverCtx), | ||
31 | + }, | ||
32 | + { | ||
33 | + Method: http.MethodDelete, | ||
34 | + Path: "/chart/:id", | ||
35 | + Handler: chart.DeleteChartHandler(serverCtx), | ||
36 | + }, | ||
37 | + { | ||
38 | + Method: http.MethodPut, | ||
39 | + Path: "/chart/:id", | ||
40 | + Handler: chart.UpdateChartHandler(serverCtx), | ||
41 | + }, | ||
42 | + { | ||
43 | + Method: http.MethodPost, | ||
44 | + Path: "/chart/search", | ||
45 | + Handler: chart.SearchChartHandler(serverCtx), | ||
46 | + }, | ||
47 | + { | ||
48 | + Method: http.MethodPost, | ||
49 | + Path: "/chart/move", | ||
50 | + Handler: chart.UpdateChartSortHandler(serverCtx), | ||
51 | + }, | ||
52 | + { | ||
53 | + Method: http.MethodPost, | ||
54 | + Path: "/chart/rename", | ||
55 | + Handler: chart.RenameChartSortHandler(serverCtx), | ||
56 | + }, | ||
57 | + { | ||
58 | + Method: http.MethodPost, | ||
59 | + Path: "/chart/components/search", | ||
60 | + Handler: chart.SearchChartComponentsHandler(serverCtx), | ||
61 | + }, | ||
62 | + }..., | ||
63 | + ), | ||
61 | rest.WithJwt(serverCtx.Config.JwtAuth.AccessSecret), | 64 | rest.WithJwt(serverCtx.Config.JwtAuth.AccessSecret), |
62 | rest.WithPrefix("/v1"), | 65 | rest.WithPrefix("/v1"), |
63 | ) | 66 | ) |
64 | 67 | ||
65 | server.AddRoutes( | 68 | server.AddRoutes( |
66 | - []rest.Route{ | ||
67 | - { | ||
68 | - Method: http.MethodPost, | ||
69 | - Path: "/chart/load-data", | ||
70 | - Handler: chart.LoadChartDataHandler(serverCtx), | ||
71 | - }, | ||
72 | - { | ||
73 | - Method: http.MethodGet, | ||
74 | - Path: "/chart/:id", | ||
75 | - Handler: chart.GetChartHandler(serverCtx), | ||
76 | - }, | ||
77 | - }, | 69 | + rest.WithMiddlewares( |
70 | + []rest.Middleware{serverCtx.LogRequest}, | ||
71 | + []rest.Route{ | ||
72 | + { | ||
73 | + Method: http.MethodPost, | ||
74 | + Path: "/chart/load-data", | ||
75 | + Handler: chart.LoadChartDataHandler(serverCtx), | ||
76 | + }, | ||
77 | + { | ||
78 | + Method: http.MethodGet, | ||
79 | + Path: "/chart/:id", | ||
80 | + Handler: chart.GetChartHandler(serverCtx), | ||
81 | + }, | ||
82 | + }..., | ||
83 | + ), | ||
78 | rest.WithPrefix("/v1"), | 84 | rest.WithPrefix("/v1"), |
79 | ) | 85 | ) |
80 | 86 | ||
@@ -105,67 +111,76 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | @@ -105,67 +111,76 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | ||
105 | ) | 111 | ) |
106 | 112 | ||
107 | server.AddRoutes( | 113 | server.AddRoutes( |
108 | - []rest.Route{ | ||
109 | - { | ||
110 | - Method: http.MethodPost, | ||
111 | - Path: "/table/search-by-module", | ||
112 | - Handler: table.SearchTableByModuleHandler(serverCtx), | ||
113 | - }, | ||
114 | - }, | 114 | + rest.WithMiddlewares( |
115 | + []rest.Middleware{serverCtx.LoginStatusCheck, serverCtx.LogRequest}, | ||
116 | + []rest.Route{ | ||
117 | + { | ||
118 | + Method: http.MethodPost, | ||
119 | + Path: "/table/search-by-module", | ||
120 | + Handler: table.SearchTableByModuleHandler(serverCtx), | ||
121 | + }, | ||
122 | + }..., | ||
123 | + ), | ||
115 | rest.WithJwt(serverCtx.Config.JwtAuth.AccessSecret), | 124 | rest.WithJwt(serverCtx.Config.JwtAuth.AccessSecret), |
116 | rest.WithPrefix("/v1"), | 125 | rest.WithPrefix("/v1"), |
117 | ) | 126 | ) |
118 | 127 | ||
119 | server.AddRoutes( | 128 | server.AddRoutes( |
120 | - []rest.Route{ | ||
121 | - { | ||
122 | - Method: http.MethodPost, | ||
123 | - Path: "/app-page", | ||
124 | - Handler: page.SaveAppPageHandler(serverCtx), | ||
125 | - }, | ||
126 | - { | ||
127 | - Method: http.MethodPost, | ||
128 | - Path: "/app-page/saveas", | ||
129 | - Handler: page.SaveAsAppPageHandler(serverCtx), | ||
130 | - }, | ||
131 | - { | ||
132 | - Method: http.MethodDelete, | ||
133 | - Path: "/app-page/:id", | ||
134 | - Handler: page.DeleteAppPageHandler(serverCtx), | ||
135 | - }, | ||
136 | - { | ||
137 | - Method: http.MethodPut, | ||
138 | - Path: "/app-page/:id", | ||
139 | - Handler: page.UpdateAppPageHandler(serverCtx), | ||
140 | - }, | ||
141 | - { | ||
142 | - Method: http.MethodPost, | ||
143 | - Path: "/app-page/search", | ||
144 | - Handler: page.SearchAppPageHandler(serverCtx), | ||
145 | - }, | ||
146 | - { | ||
147 | - Method: http.MethodPost, | ||
148 | - Path: "/app-page/create-share", | ||
149 | - Handler: page.CreateAppPageShareUrlHandler(serverCtx), | ||
150 | - }, | ||
151 | - }, | 129 | + rest.WithMiddlewares( |
130 | + []rest.Middleware{serverCtx.LoginStatusCheck, serverCtx.LogRequest}, | ||
131 | + []rest.Route{ | ||
132 | + { | ||
133 | + Method: http.MethodPost, | ||
134 | + Path: "/app-page", | ||
135 | + Handler: page.SaveAppPageHandler(serverCtx), | ||
136 | + }, | ||
137 | + { | ||
138 | + Method: http.MethodPost, | ||
139 | + Path: "/app-page/saveas", | ||
140 | + Handler: page.SaveAsAppPageHandler(serverCtx), | ||
141 | + }, | ||
142 | + { | ||
143 | + Method: http.MethodDelete, | ||
144 | + Path: "/app-page/:id", | ||
145 | + Handler: page.DeleteAppPageHandler(serverCtx), | ||
146 | + }, | ||
147 | + { | ||
148 | + Method: http.MethodPut, | ||
149 | + Path: "/app-page/:id", | ||
150 | + Handler: page.UpdateAppPageHandler(serverCtx), | ||
151 | + }, | ||
152 | + { | ||
153 | + Method: http.MethodPost, | ||
154 | + Path: "/app-page/search", | ||
155 | + Handler: page.SearchAppPageHandler(serverCtx), | ||
156 | + }, | ||
157 | + { | ||
158 | + Method: http.MethodPost, | ||
159 | + Path: "/app-page/create-share", | ||
160 | + Handler: page.CreateAppPageShareUrlHandler(serverCtx), | ||
161 | + }, | ||
162 | + }..., | ||
163 | + ), | ||
152 | rest.WithJwt(serverCtx.Config.JwtAuth.AccessSecret), | 164 | rest.WithJwt(serverCtx.Config.JwtAuth.AccessSecret), |
153 | rest.WithPrefix("/v1"), | 165 | rest.WithPrefix("/v1"), |
154 | ) | 166 | ) |
155 | 167 | ||
156 | server.AddRoutes( | 168 | server.AddRoutes( |
157 | - []rest.Route{ | ||
158 | - { | ||
159 | - Method: http.MethodGet, | ||
160 | - Path: "/app-page/:id", | ||
161 | - Handler: page.GetAppPageHandler(serverCtx), | ||
162 | - }, | ||
163 | - { | ||
164 | - Method: http.MethodGet, | ||
165 | - Path: "/api/app-page/get-share-detail/:key", | ||
166 | - Handler: page.GetAppPageShareDetailHandler(serverCtx), | ||
167 | - }, | ||
168 | - }, | 169 | + rest.WithMiddlewares( |
170 | + []rest.Middleware{serverCtx.LogRequest}, | ||
171 | + []rest.Route{ | ||
172 | + { | ||
173 | + Method: http.MethodGet, | ||
174 | + Path: "/app-page/:id", | ||
175 | + Handler: page.GetAppPageHandler(serverCtx), | ||
176 | + }, | ||
177 | + { | ||
178 | + Method: http.MethodGet, | ||
179 | + Path: "/api/app-page/get-share-detail/:key", | ||
180 | + Handler: page.GetAppPageShareDetailHandler(serverCtx), | ||
181 | + }, | ||
182 | + }..., | ||
183 | + ), | ||
169 | rest.WithPrefix("/v1"), | 184 | rest.WithPrefix("/v1"), |
170 | ) | 185 | ) |
171 | 186 |
1 | +package middleware | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/zeromicro/go-zero/rest/httpx" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway/authlib" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/result" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xerr" | ||
9 | + "net/http" | ||
10 | +) | ||
11 | + | ||
12 | +type LoginStatusCheckMiddleware struct { | ||
13 | + apiAuth authlib.ApiAuthService | ||
14 | +} | ||
15 | + | ||
16 | +func NewLoginStatusCheckMiddleware(apiAuth authlib.ApiAuthService) *LoginStatusCheckMiddleware { | ||
17 | + return &LoginStatusCheckMiddleware{ | ||
18 | + apiAuth: apiAuth, | ||
19 | + } | ||
20 | +} | ||
21 | + | ||
22 | +func (m *LoginStatusCheckMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc { | ||
23 | + return func(w http.ResponseWriter, r *http.Request) { | ||
24 | + token := r.Header.Get("x-mmm-accesstoken") | ||
25 | + if len(token) > 0 { | ||
26 | + _, err := m.apiAuth.LoginCheck(r.Context(), authlib.RequestLoginCheck{ | ||
27 | + Token: token, | ||
28 | + }) | ||
29 | + if err != nil { | ||
30 | + gatewayError, ok := err.(gateway.HttpError) | ||
31 | + if ok { | ||
32 | + unAuthResponse(w, gatewayError.Base.Code, gatewayError.Base.Msg) | ||
33 | + return | ||
34 | + } | ||
35 | + result.HttpResult(r, w, struct{}{}, xerr.NewErr(err)) | ||
36 | + return | ||
37 | + } | ||
38 | + } | ||
39 | + next(w, r) | ||
40 | + } | ||
41 | +} | ||
42 | + | ||
43 | +func unAuthResponse(w http.ResponseWriter, code int, msg string) { | ||
44 | + data := map[string]interface{}{ | ||
45 | + "msg": msg, | ||
46 | + "code": code, | ||
47 | + "data": struct{}{}, | ||
48 | + } | ||
49 | + httpx.WriteJson(w, http.StatusUnauthorized, data) | ||
50 | +} |
1 | +package middleware | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/zeromicro/go-zero/rest/handler" | ||
5 | + "net/http" | ||
6 | +) | ||
7 | + | ||
8 | +type LogRequestMiddleware struct { | ||
9 | + logRequest bool | ||
10 | +} | ||
11 | + | ||
12 | +// NewLogRequestMiddleware 记录请求 | ||
13 | +// logRequest true开启记录,false关闭记录 | ||
14 | +func NewLogRequestMiddleware(logRequest bool) *LogRequestMiddleware { | ||
15 | + return &LogRequestMiddleware{ | ||
16 | + logRequest: logRequest, | ||
17 | + } | ||
18 | +} | ||
19 | + | ||
20 | +func (m *LogRequestMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc { | ||
21 | + if !m.logRequest { | ||
22 | + return func(writer http.ResponseWriter, request *http.Request) { | ||
23 | + next(writer, request) | ||
24 | + } | ||
25 | + } | ||
26 | + return handler.DetailedLogHandler(next).(http.HandlerFunc) | ||
27 | +} |
@@ -3,11 +3,14 @@ package svc | @@ -3,11 +3,14 @@ package svc | ||
3 | import ( | 3 | import ( |
4 | "github.com/tiptok/gocomm/pkg/cache/gzcache" | 4 | "github.com/tiptok/gocomm/pkg/cache/gzcache" |
5 | "github.com/zeromicro/go-zero/core/stores/redis" | 5 | "github.com/zeromicro/go-zero/core/stores/redis" |
6 | + "github.com/zeromicro/go-zero/rest" | ||
6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/config" | 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/config" |
8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/middleware" | ||
7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/repository" | 9 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/repository" |
8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/transaction" | 10 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/transaction" |
9 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain" | 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain" |
10 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway" | 12 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway" |
13 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway/authlib" | ||
11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway/bytelib" | 14 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway/bytelib" |
12 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/cache" | 15 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/cache" |
13 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/database" | 16 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/database" |
@@ -27,6 +30,10 @@ type ServiceContext struct { | @@ -27,6 +30,10 @@ type ServiceContext struct { | ||
27 | ObjectFieldRepository domain.ObjectFieldRepository | 30 | ObjectFieldRepository domain.ObjectFieldRepository |
28 | ObjectTableDataRepository domain.ObjectTableDataRepository | 31 | ObjectTableDataRepository domain.ObjectTableDataRepository |
29 | 32 | ||
33 | + ApiAuthService authlib.ApiAuthService | ||
34 | + LoginStatusCheck rest.Middleware | ||
35 | + LogRequest rest.Middleware | ||
36 | + | ||
30 | ByteMetadataService bytelib.ByteMetadataService | 37 | ByteMetadataService bytelib.ByteMetadataService |
31 | } | 38 | } |
32 | 39 | ||
@@ -35,12 +42,17 @@ func NewServiceContext(c config.Config) *ServiceContext { | @@ -35,12 +42,17 @@ func NewServiceContext(c config.Config) *ServiceContext { | ||
35 | mlCache := cache.NewMultiLevelCache([]string{c.Redis.Host}, c.Redis.Pass) | 42 | mlCache := cache.NewMultiLevelCache([]string{c.Redis.Host}, c.Redis.Pass) |
36 | redisCache := gzcache.NewClusterCache([]string{c.Redis.Host}, c.Redis.Pass) | 43 | redisCache := gzcache.NewClusterCache([]string{c.Redis.Host}, c.Redis.Pass) |
37 | redis, _ := redis.NewRedis(redis.RedisConf{Host: c.Redis.Host, Pass: c.Redis.Pass, Type: "node"}) | 44 | redis, _ := redis.NewRedis(redis.RedisConf{Host: c.Redis.Host, Pass: c.Redis.Pass, Type: "node"}) |
38 | - | 45 | + apiAuth := authlib.ApiAuthService{ |
46 | + Service: gateway.NewService(c.ApiAuth.Name, c.ApiAuth.Host, c.ApiAuth.Timeout), | ||
47 | + } | ||
39 | return &ServiceContext{ | 48 | return &ServiceContext{ |
40 | Config: c, | 49 | Config: c, |
41 | DB: db, | 50 | DB: db, |
42 | RedisCache: redisCache, | 51 | RedisCache: redisCache, |
43 | Redis: redis, | 52 | Redis: redis, |
53 | + ApiAuthService: apiAuth, | ||
54 | + LoginStatusCheck: middleware.NewLoginStatusCheckMiddleware(apiAuth).Handle, | ||
55 | + LogRequest: middleware.NewLogRequestMiddleware(c.LogRequest).Handle, | ||
44 | ChartRepository: repository.NewChartRepository(cache.NewCachedRepository(mlCache)), | 56 | ChartRepository: repository.NewChartRepository(cache.NewCachedRepository(mlCache)), |
45 | ChartSettingRepository: repository.NewChartSettingRepository(cache.NewCachedRepository(mlCache)), | 57 | ChartSettingRepository: repository.NewChartSettingRepository(cache.NewCachedRepository(mlCache)), |
46 | AppPageRepository: repository.NewAppPageRepository(cache.NewCachedRepository(mlCache)), | 58 | AppPageRepository: repository.NewAppPageRepository(cache.NewCachedRepository(mlCache)), |
1 | +package authlib | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/gateway" | ||
6 | + "net/http" | ||
7 | +) | ||
8 | + | ||
9 | +type ApiAuthService struct { | ||
10 | + gateway.Service | ||
11 | +} | ||
12 | + | ||
13 | +func (svc *ApiAuthService) MeInfo(ctx context.Context, request RequestUserMeQuery) (*DataUserMe, error) { | ||
14 | + var result DataUserMe | ||
15 | + if err := svc.Do(ctx, "/v1/user/me", http.MethodGet, request, &result); err != nil { | ||
16 | + return nil, err | ||
17 | + } | ||
18 | + return &result, nil | ||
19 | +} | ||
20 | + | ||
21 | +func (svc *ApiAuthService) MeAppInfo(ctx context.Context, request RequestUserMeQuery) (*DataUserAppInfo, error) { | ||
22 | + var result DataUserAppInfo | ||
23 | + if err := svc.Do(ctx, "/v1/user/me-app-info", http.MethodGet, request, &result); err != nil { | ||
24 | + return nil, err | ||
25 | + } | ||
26 | + return &result, nil | ||
27 | +} | ||
28 | + | ||
29 | +func (svc *ApiAuthService) LoginCheck(ctx context.Context, request RequestLoginCheck) (*DataLoginCheck, error) { | ||
30 | + var ( | ||
31 | + result DataLoginCheck | ||
32 | + err error | ||
33 | + ) | ||
34 | + if err = svc.Do(ctx, "/v1/login/check?token="+request.Token, http.MethodGet, request, &result); err != nil { | ||
35 | + return nil, err | ||
36 | + } | ||
37 | + if errCodeMsg, ok := err.(gateway.HttpError); ok { | ||
38 | + return &DataLoginCheck{ | ||
39 | + Code: errCodeMsg.Base.Code, | ||
40 | + Msg: errCodeMsg.Base.Msg, | ||
41 | + }, nil | ||
42 | + } | ||
43 | + return &result, nil | ||
44 | +} | ||
45 | + | ||
46 | +func (svc *ApiAuthService) AppLogin(ctx context.Context, request RequestAppLogin) (*DataAppLogin, error) { | ||
47 | + var result DataAppLogin | ||
48 | + if err := svc.Do(ctx, "/v1/login/check?token="+request.Token, http.MethodGet, request, &result); err != nil { | ||
49 | + return nil, err | ||
50 | + } | ||
51 | + return &result, nil | ||
52 | +} |
1 | +package authlib | ||
2 | + | ||
3 | +type RequestUserMeQuery struct { | ||
4 | + Token string `header:"x-mmm-accesstoken"` | ||
5 | + //UserId int | ||
6 | + //CompanyId int | ||
7 | +} | ||
8 | + | ||
9 | +type DataUserMe struct { | ||
10 | + User *struct { | ||
11 | + ID string `json:"id"` | ||
12 | + Phone string `json:"phone"` | ||
13 | + NickName string `json:"nickName"` | ||
14 | + Avatar string `json:"avatar"` | ||
15 | + } `json:"user,optional"` | ||
16 | + CompanyList []*struct { | ||
17 | + ID string `json:"id"` | ||
18 | + Name string `json:"name"` | ||
19 | + Logo string `json:"logo"` | ||
20 | + DefaultLogin int `json:"defaultLogin"` | ||
21 | + Types int `json:"types"` | ||
22 | + } `json:"companyList,optional"` | ||
23 | + CurrentCompany *struct { | ||
24 | + ID string `json:"id"` | ||
25 | + Name string `json:"name"` | ||
26 | + Logo string `json:"logo"` | ||
27 | + DefaultLogin int `json:"defaultLogin"` | ||
28 | + Types int `json:"types"` | ||
29 | + } `json:"currentCompany,optional"` | ||
30 | + Workbench []*struct { | ||
31 | + ID int `json:"id"` | ||
32 | + Name string `json:"name"` | ||
33 | + Code string `json:"code"` | ||
34 | + CoverImage string `json:"coverImage"` | ||
35 | + URL string `json:"url"` | ||
36 | + } `json:"workbench,optional"` | ||
37 | + Menus []*struct { | ||
38 | + MenuID int `json:"menuId"` | ||
39 | + ParentID int `json:"parentId"` | ||
40 | + MenuName string `json:"menuName"` | ||
41 | + Code string `json:"code"` | ||
42 | + Types string `json:"types"` | ||
43 | + } `json:"menus,optional"` | ||
44 | +} | ||
45 | + | ||
46 | +type RequestLoginCheck struct { | ||
47 | + Token string | ||
48 | +} | ||
49 | +type DataLoginCheck struct { | ||
50 | + Code int `json:"code,optional"` | ||
51 | + Msg string `json:"msg,optional"` | ||
52 | +} | ||
53 | + | ||
54 | +type ( | ||
55 | + RequestAppLogin struct { | ||
56 | + AppKey string `json:"appKey" valid:"Required"` // 应用键值 | ||
57 | + Token string `json:"token" valid:"Required"` // 凭证 | ||
58 | + } | ||
59 | + DataAppLogin struct { | ||
60 | + AppEnabled bool `json:"appEnabled"` | ||
61 | + } | ||
62 | +) | ||
63 | + | ||
64 | +type ( | ||
65 | + DataUserAppInfo struct { | ||
66 | + Apps []AppItem `json:"apps"` | ||
67 | + } | ||
68 | + AppItem struct { | ||
69 | + AppId int64 | ||
70 | + AppKey string | ||
71 | + AppName string | ||
72 | + } | ||
73 | +) |
@@ -13,6 +13,7 @@ info( | @@ -13,6 +13,7 @@ info( | ||
13 | prefix: v1 | 13 | prefix: v1 |
14 | group: page | 14 | group: page |
15 | jwt: JwtAuth | 15 | jwt: JwtAuth |
16 | + middleware: LoginStatusCheck,LogRequest | ||
16 | ) | 17 | ) |
17 | service Core { | 18 | service Core { |
18 | @doc "保存应用页" | 19 | @doc "保存应用页" |
@@ -108,6 +109,7 @@ type ( | @@ -108,6 +109,7 @@ type ( | ||
108 | @server( | 109 | @server( |
109 | prefix: v1 | 110 | prefix: v1 |
110 | group: page | 111 | group: page |
112 | + middleware: LogRequest | ||
111 | ) | 113 | ) |
112 | service Core { | 114 | service Core { |
113 | @doc "获取应用页详情" | 115 | @doc "获取应用页详情" |
@@ -12,7 +12,7 @@ info( | @@ -12,7 +12,7 @@ info( | ||
12 | prefix: v1 | 12 | prefix: v1 |
13 | group: chart | 13 | group: chart |
14 | jwt: JwtAuth | 14 | jwt: JwtAuth |
15 | - //middleware: Authority | 15 | + middleware: LoginStatusCheck,LogRequest |
16 | ) | 16 | ) |
17 | service Core { | 17 | service Core { |
18 | @doc "保存图表" | 18 | @doc "保存图表" |
@@ -45,6 +45,7 @@ service Core { | @@ -45,6 +45,7 @@ service Core { | ||
45 | @server( | 45 | @server( |
46 | prefix: v1 | 46 | prefix: v1 |
47 | group: chart | 47 | group: chart |
48 | + middleware: LogRequest | ||
48 | ) | 49 | ) |
49 | service Core { | 50 | service Core { |
50 | @doc "加载图表数据" | 51 | @doc "加载图表数据" |
@@ -13,6 +13,7 @@ info( | @@ -13,6 +13,7 @@ info( | ||
13 | prefix: v1 | 13 | prefix: v1 |
14 | group: chart-setting | 14 | group: chart-setting |
15 | jwt: JwtAuth | 15 | jwt: JwtAuth |
16 | + middleware: LoginStatusCheck,LogRequest | ||
16 | ) | 17 | ) |
17 | service Core { | 18 | service Core { |
18 | @handler getChartSetting | 19 | @handler getChartSetting |
@@ -36,6 +36,7 @@ service Core { | @@ -36,6 +36,7 @@ service Core { | ||
36 | prefix: v1 | 36 | prefix: v1 |
37 | group: table | 37 | group: table |
38 | jwt: JwtAuth | 38 | jwt: JwtAuth |
39 | + middleware: LoginStatusCheck,LogRequest | ||
39 | //middleware: Authority | 40 | //middleware: Authority |
40 | ) | 41 | ) |
41 | service Core { | 42 | service Core { |
-
请 注册 或 登录 后发表评论