LingxinMeng vor 7 Monaten
Ursprung
Commit
fa53e76985
2 geänderte Dateien mit 16 neuen und 10 gelöschten Zeilen
  1. 2 0
      README.md
  2. 14 10
      src/package/handler/start_project.go

+ 2 - 0
README.md

@@ -3,3 +3,5 @@
 # 依赖
 1. Redis
 # 部署
+## 服务器
+gpu001

+ 14 - 10
src/package/handler/start_project.go

@@ -1,11 +1,13 @@
 package handler
 
 import (
+	"bytes"
 	"dcl_dispatch_server/src/package/domain"
 	"dcl_dispatch_server/src/package/entity"
 	"dcl_dispatch_server/src/package/global"
 	"dcl_dispatch_server/src/package/infra"
 	"github.com/gin-gonic/gin"
+	"io"
 	"net/http"
 )
 
@@ -117,20 +119,22 @@ import (
 */
 
 func StartProject(c *gin.Context) {
-	//// 读取请求体
-	//bodyBytes, err := io.ReadAll(c.Request.Body)
-	//if err != nil {
-	//	c.String(500, "Error reading request body")
-	//	return
-	//}
-	//// 将请求体转换为字符串
-	//bodyString := string(bodyBytes)
-	//infra.GlobalLogger.Info("项目启动接收请求参数为:", bodyString)
 
 	projectStartParam := new(entity.Project)
+	bodyBytes, err := io.ReadAll(c.Request.Body)
+	if err != nil {
+		infra.GlobalLogger.Error("读取请求体失败:", err)
+		c.JSON(http.StatusOK, entity.HttpResult{Status: false, Code: "400", Message: "读取请求体失败。"})
+		return
+	}
+
+	// 重新将读取的请求体存入 body 中,因为 ioutil.ReadAll 会将 body 中的数据读取完
+	c.Request.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
+
 	if err := c.ShouldBindJSON(&projectStartParam); err != nil {
 		infra.GlobalLogger.Error("项目启动接收请求参数报错:", err)
-		c.JSON(http.StatusBadRequest, entity.HttpResult{Status: false, Code: "1003", Message: "请求参数格式错误。"})
+		infra.GlobalLogger.Error("原始请求体:", string(bodyBytes))
+		c.JSON(http.StatusOK, entity.HttpResult{Status: false, Code: "400", Message: "请求参数格式错误。"})
 		return
 	}
 	if !checkEquipmentType(projectStartParam.EquipmentType) {