From 3975846f775c0ec8412f8c273fcdba01adc4f09c Mon Sep 17 00:00:00 2001 From: ShenQiLun <97694732@qq.com> Date: Fri, 26 Jun 2026 17:18:01 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=94=B6=E5=88=B0=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E5=92=8Cisbn=3D0=E6=97=A5=E5=BF=97=E6=AF=8F20?= =?UTF-8?q?=E6=AC=A1=E6=89=93=E5=8D=B0=E4=B8=80=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/handler/goods_handler.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/handler/goods_handler.go b/internal/handler/goods_handler.go index e3cff7d..847c099 100644 --- a/internal/handler/goods_handler.go +++ b/internal/handler/goods_handler.go @@ -7,6 +7,7 @@ import ( "log" "net/http" "strconv" + "sync/atomic" "kfz-goods-pricing/internal/service" ) @@ -14,6 +15,7 @@ import ( // GoodsHandler 商品处理器 type GoodsHandler struct { goodsService *service.GoodsService + reqCount int64 } // NewGoodsHandler 创建商品处理器实例 @@ -25,11 +27,15 @@ func NewGoodsHandler(goodsService *service.GoodsService) *GoodsHandler { // QueryGoods 查询商品接口 func (h *GoodsHandler) QueryGoods(w http.ResponseWriter, r *http.Request) { + count := atomic.AddInt64(&h.reqCount, 1) + clientIP := r.RemoteAddr if forwarded := r.Header.Get("X-Forwarded-For"); forwarded != "" { clientIP = forwarded } - log.Printf("[QueryGoods] 收到请求, 来源IP: %s, Method: %s", clientIP, r.Method) + if count%20 == 1 { + log.Printf("[QueryGoods] 收到请求, 来源IP: %s, Method: %s", clientIP, r.Method) + } // 只支持POST请求 if r.Method != http.MethodPost { @@ -56,7 +62,9 @@ func (h *GoodsHandler) QueryGoods(w http.ResponseWriter, r *http.Request) { isbn := r.FormValue("isbn") if isbn == "0" { - log.Printf("[QueryGoods] 收到请求 isbn=0") + if count%20 == 1 { + log.Printf("[QueryGoods] 收到请求 isbn=0") + } var req service.QueryRequest req.ISBN = isbn resp := h.goodsService.QueryGoods(&req)