1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package gateway
- import (
- "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 *RequestBuilderContext) {
- c.apiContext.Status(http.StatusOK)
- if c.historyRequests != nil && len(c.historyRequests) != 0 {
- _, err := c.apiContext.Writer.Write(c.historyRequests[len(c.historyRequests)-1].Response().Body())
- if err != nil {
- logger.GetInstance().Error(errors.New(err.Error()))
- c.apiContext.AbortWithStatus(http.StatusInternalServerError)
- return
- }
- }
- c.apiContext.Writer.Flush()
- },
- responseErrorCallback: func(c *RequestBuilderContext, 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.apiContext.JSON(http.StatusOK, resp)
- },
- }
- }
|