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 builderParams struct { httpMethod string relativePath string requestItems []*builderRequestItem globalRequestResponseCallback GlobalRequestResponseCallback responseSuccessCallback ResponseSuccessCallback responseErrorCallback ResponseErrorCallback } func newBuilderParams() *builderParams { return &builderParams{ httpMethod: "", relativePath: "", requestItems: make([]*builderRequestItem, 0), globalRequestResponseCallback: nil, responseSuccessCallback: func(c *api.Context, historyRequests []BuilderRequest, customResultMap 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, 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) }, } } func (params *builderParams) copy() *builderParams { return &builderParams{ httpMethod: params.httpMethod, relativePath: params.relativePath, requestItems: params.requestItems, globalRequestResponseCallback: params.globalRequestResponseCallback, responseSuccessCallback: params.responseSuccessCallback, responseErrorCallback: params.responseErrorCallback, } }