package gateway import ( "git.sxidc.com/go-framework/baize/framework/core/api" "git.sxidc.com/go-framework/baize/framework/core/infrastructure/logger" "git.sxidc.com/service-supports/fserr" "net/http" ) type builderParams struct { httpMethod string relativePath string requestItems []*builderRequestItem globalRequestCallbackFunc GlobalRequestCallbackFunc responseSuccessFunc ResponseSuccessFunc responseErrorFunc ResponseErrorFunc } func newBuilderParams() *builderParams { return &builderParams{ httpMethod: "", relativePath: "", requestItems: make([]*builderRequestItem, 0), globalRequestCallbackFunc: nil, responseSuccessFunc: func(c *api.Context, historyRequests []BuilderRequest, customResultMap map[string]any) { c.Status(http.StatusOK) _, err := c.Writer.Write(historyRequests[len(historyRequests)-1].Response().Body()) if err != nil { logger.GetInstance().Error(fserr.New(err.Error())) c.AbortWithStatus(http.StatusInternalServerError) return } c.Writer.Flush() }, responseErrorFunc: func(c *api.Context, err error) { if err == nil { return } resp := make(map[string]any) logger.GetInstance().Error(err) serviceErr := fserr.ParseCode(err) resp["success"] = false resp["errCode"] = serviceErr.BusinessCode resp["msg"] = serviceErr.Msg c.JSON(http.StatusOK, resp) }, } } func (params *builderParams) copy() *builderParams { return &builderParams{ httpMethod: params.httpMethod, relativePath: params.relativePath, requestItems: params.requestItems, globalRequestCallbackFunc: params.globalRequestCallbackFunc, responseSuccessFunc: params.responseSuccessFunc, responseErrorFunc: params.responseErrorFunc, } }