package middleware import ( "bytes" "git.sxidc.com/go-tools/api_binding/http_binding/binding_context" "git.sxidc.com/go-tools/api_binding/http_binding/response" "git.sxidc.com/service-supports/fslog" "io" "net/http" ) func ReadRequestBodyData() Func { return func(c *binding_context.Context) { respFunc := response.SendMsgResponse contentType := c.Request.Header.Get("Content-Type") if c.Request.Body != nil && contentType == "application/json" && (c.Request.Method == http.MethodPost || c.Request.Method == http.MethodPut) { bodyData, err := io.ReadAll(c.Request.Body) if err != nil { respFunc(c, http.StatusBadRequest, nil, err) c.Abort() return } fslog.Info(c.Request.RequestURI + " Request Body\n" + string(bodyData)) _ = c.Request.Body.Close() c.Request.Body = nil c.Request.Body = io.NopCloser(bytes.NewReader(bodyData)) } c.Next() } }