refactor: isbn=0时只输出收到请求isbn=0, 忽略详细参数日志

This commit is contained in:
ShenQiLun 2026-06-26 17:08:44 +08:00
parent aa8bcae334
commit 4f1307b49e
3 changed files with 12 additions and 3 deletions

Binary file not shown.

View File

@ -40,8 +40,6 @@ func (h *GoodsHandler) QueryGoods(w http.ResponseWriter, r *http.Request) {
// 读取原始body用于调试 // 读取原始body用于调试
bodyBytes, _ := io.ReadAll(r.Body) bodyBytes, _ := io.ReadAll(r.Body)
bodyStr := string(bodyBytes)
log.Printf("[QueryGoods] 原始请求 Body: [%s], Content-Type: [%s]", bodyStr, r.Header.Get("Content-Type"))
// 重新创建body供ParseForm使用 // 重新创建body供ParseForm使用
r.Body = io.NopCloser(bytes.NewBuffer(bodyBytes)) r.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
@ -57,6 +55,17 @@ func (h *GoodsHandler) QueryGoods(w http.ResponseWriter, r *http.Request) {
} }
isbn := r.FormValue("isbn") isbn := r.FormValue("isbn")
if isbn == "0" {
log.Printf("[QueryGoods] 收到请求 isbn=0")
var req service.QueryRequest
req.ISBN = isbn
resp := h.goodsService.QueryGoods(&req)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(resp)
return
}
bookName := r.FormValue("book_name") bookName := r.FormValue("book_name")
author := r.FormValue("author") author := r.FormValue("author")
publishing := r.FormValue("publishing") publishing := r.FormValue("publishing")

View File

@ -67,7 +67,7 @@ type QueryResponse struct {
// QueryGoods 查询商品信息 // QueryGoods 查询商品信息
func (s *GoodsService) QueryGoods(req *QueryRequest) *QueryResponse { func (s *GoodsService) QueryGoods(req *QueryRequest) *QueryResponse {
if req.ISBN == "0" { if req.ISBN == "0" {
log.Printf("[QueryGoods] ISBN为0, 跳过处理") log.Printf("[QueryGoods] 收到请求 isbn=0")
return &QueryResponse{ return &QueryResponse{
Code: 200, Code: 200,
Message: "success", Message: "success",