package gateway import ( "git.sxidc.com/go-framework/baize/framework/core/api" "git.sxidc.com/go-framework/baize/framework/core/infrastructure/logger" "github.com/pkg/errors" "net/http" ) type requestBuilderParams struct { requestItems []*builderRequestItem responseSuccessCallback ResponseSuccessCallback responseErrorCallback ResponseErrorCallback } func newRequestBuilderParams() *requestBuilderParams { return &requestBuilderParams{ requestItems: make([]*builderRequestItem, 0), responseSuccessCallback: func(c *api.Context, historyRequests []Request, resultMap map[string]any) { c.Status(http.StatusOK) if historyRequests != nil && len(historyRequests) != 0 { _, err := c.Writer.Write(historyRequests[len(historyRequests)-1].Response().Body()) if err != nil { logger.GetInstance().Error(errors.New(err.Error())) c.AbortWithStatus(http.StatusInternalServerError) return } } c.Writer.Flush() }, responseErrorCallback: func(c *api.Context, historyRequests []Request, resultMap map[string]any, err error) { if err == nil { return } resp := make(map[string]any) logger.GetInstance().Error(err) resp["success"] = false resp["errCode"] = http.StatusOK resp["msg"] = err.Error() c.JSON(http.StatusOK, resp) }, } }