| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- 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,
- }
- }
|