소스 검색

增加禁止缓存中间件

fuwencai 3 년 전
부모
커밋
468145162e
3개의 변경된 파일20개의 추가작업 그리고 5개의 파일을 삭제
  1. 2 2
      api/deduplication.api
  2. 16 1
      api/deduplication.go
  3. 2 2
      api/internal/handler/routes.go

+ 2 - 2
api/deduplication.api

@@ -51,7 +51,7 @@ service deduplication-api {
 	@handler GetEntCount // 调用数据去重
 	post /data/getEntCount (EntCountReq) returns (EntCountResp)
 	@handler dedupByAcount // 根据账户id判重
-	post /data/dedupByAcount (DedupByAccountReq) returns (DedupResp)
+	post /data/dedupByAcount/:id (DedupByAccountReq) returns (DedupResp)
 	@handler dedupAndSave // 根据账户id判重并存入数据
-	post /data/dedupAndSave (DedupByAccountReq) returns (DedupResp)
+	post /data/dedupAndSave/:id (DedupByAccountReq) returns (DedupResp)
 }

+ 16 - 1
api/deduplication.go

@@ -3,6 +3,8 @@ package main
 import (
 	"flag"
 	"fmt"
+	"log"
+	"net/http"
 
 	"app.yhyue.com/moapp/dataDeduplication/api/internal/config"
 	"app.yhyue.com/moapp/dataDeduplication/api/internal/handler"
@@ -23,7 +25,20 @@ func main() {
 	ctx := svc.NewServiceContext(c)
 	server := rest.MustNewServer(c.RestConf)
 	defer server.Stop()
-
+	//追加防止缓存中间件
+	noCacheMiddleware := rest.ToMiddleware(func(next http.Handler) http.Handler {
+
+		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+			log.Println(r.URL,"232")
+			defer func() {
+				w.Header().Set("Pragma", "no-cache")
+				w.Header().Set("Cache-Control", "no-cache")
+				w.Header().Set("Expires", "0")
+			}()
+			next.ServeHTTP(w, r)
+		})
+	})
+	server.Use(noCacheMiddleware)
 	handler.RegisterHandlers(server, ctx)
 
 	fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)

+ 2 - 2
api/internal/handler/routes.go

@@ -24,12 +24,12 @@ func RegisterHandlers(engine *rest.Server, serverCtx *svc.ServiceContext) {
 			},
 			{
 				Method:  http.MethodPost,
-				Path:    "/data/dedupByAcount",
+				Path:    "/data/dedupByAcount/:id",
 				Handler: dedupByAcountHandler(serverCtx),
 			},
 			{
 				Method:  http.MethodPost,
-				Path:    "/data/dedupAndSave",
+				Path:    "/data/dedupAndSave/:id",
 				Handler: dedupAndSaveHandler(serverCtx),
 			},
 		},