package gateway import ( "git.sxidc.com/go-framework/baize/framework/core/infrastructure/logger" "github.com/pkg/errors" "net/http" ) type requestBuilderParams struct { httpMethod string relativePath string requestItems []*builderRequestItem responseSuccessCallback ResponseSuccessCallback responseErrorCallback ResponseErrorCallback } func newRequestBuilderParams() *requestBuilderParams { return &requestBuilderParams{ httpMethod: "", relativePath: "", requestItems: make([]*builderRequestItem, 0), responseSuccessCallback: func(requestBuilder *RequestBuilder) { requestBuilder.c.Status(http.StatusOK) if requestBuilder.historyRequests != nil && len(requestBuilder.historyRequests) != 0 { _, err := requestBuilder.c.Writer.Write(requestBuilder.historyRequests[len(requestBuilder.historyRequests)-1].Response().Body()) if err != nil { logger.GetInstance().Error(errors.New(err.Error())) requestBuilder.c.AbortWithStatus(http.StatusInternalServerError) return } } requestBuilder.c.Writer.Flush() }, responseErrorCallback: func(requestBuilder *RequestBuilder, 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() requestBuilder.c.JSON(http.StatusOK, resp) }, } }