Browse Source

封装RequestBuilderContext

yjp 7 months ago
parent
commit
d3c504dcec

+ 4 - 4
convenient/domain_gateway/configuration/configuration.go

@@ -82,7 +82,7 @@ func BuildGateway(gw *gateway.Gateway, opts ...Option) {
 	builder.
 		PostRoute("/configuration/create",
 			func(requestBuilder *gateway.RequestBuilder) {
-				jsonBody, err := requestBuilder.Context().GetJsonBody()
+				jsonBody, err := requestBuilder.ApiContext().GetJsonBody()
 				if err != nil {
 					requestBuilder.ResponseError(err)
 					return
@@ -133,7 +133,7 @@ func BuildGateway(gw *gateway.Gateway, opts ...Option) {
 	builder.
 		PostRoute("/configuration/delete",
 			func(requestBuilder *gateway.RequestBuilder) {
-				jsonBody, err := requestBuilder.Context().GetJsonBody()
+				jsonBody, err := requestBuilder.ApiContext().GetJsonBody()
 				if err != nil {
 					requestBuilder.ResponseError(err)
 					return
@@ -184,7 +184,7 @@ func BuildGateway(gw *gateway.Gateway, opts ...Option) {
 	builder.
 		GetRoute("/configuration/values",
 			func(requestBuilder *gateway.RequestBuilder) {
-				queryParams := requestBuilder.Context().GetQueryParams()
+				queryParams := requestBuilder.ApiContext().GetQueryParams()
 
 				serviceShortName := queryParams.Get("serviceShortName")
 				if strutils.IsStringEmpty(serviceShortName) {
@@ -236,7 +236,7 @@ func BuildGateway(gw *gateway.Gateway, opts ...Option) {
 				return true
 			})
 
-			requestBuilder.Context().JSON(http.StatusOK, gin.H{
+			requestBuilder.ApiContext().JSON(http.StatusOK, gin.H{
 				"services": serviceShortNames,
 			})
 		}, queryRegisteredServicesMiddlewares...)

+ 4 - 4
convenient/domain_gateway/sql_executor/sql_executor.go

@@ -73,7 +73,7 @@ func BuildGateway(gw *gateway.Gateway, opts ...Option) {
 	builder.
 		PostRouteWithUserIDCommon("/sql/execute", "executorId",
 			func(requestBuilder *gateway.RequestBuilder) {
-				jsonBody, err := requestBuilder.Context().GetJsonBody()
+				jsonBody, err := requestBuilder.ApiContext().GetJsonBody()
 				if err != nil {
 					requestBuilder.ResponseError(err)
 					return
@@ -113,7 +113,7 @@ func BuildGateway(gw *gateway.Gateway, opts ...Option) {
 					serviceUrl = innerServiceUrl
 				}
 
-				userInfo := requestBuilder.Context().GetUserInfo()
+				userInfo := requestBuilder.ApiContext().GetUserInfo()
 				if userInfo == nil {
 					jsonBody.Set("executorName", "guest")
 				} else {
@@ -130,7 +130,7 @@ func BuildGateway(gw *gateway.Gateway, opts ...Option) {
 	builder.
 		GetRouteWithUserIDCommon("/sql/execute/log", "executorId",
 			func(requestBuilder *gateway.RequestBuilder) {
-				queryParams := requestBuilder.Context().GetQueryParams()
+				queryParams := requestBuilder.ApiContext().GetQueryParams()
 
 				serviceShortName := queryParams.Get("serviceShortName")
 				if strutils.IsStringEmpty(serviceShortName) {
@@ -183,7 +183,7 @@ func BuildGateway(gw *gateway.Gateway, opts ...Option) {
 					return true
 				})
 
-				requestBuilder.Context().JSON(http.StatusOK, gin.H{
+				requestBuilder.ApiContext().JSON(http.StatusOK, gin.H{
 					"services": serviceShortNames,
 				})
 			}, queryRegisteredServicesMiddlewares...)

+ 44 - 45
convenient/gwtools/entity_crud/entity_crud.go

@@ -1,7 +1,6 @@
 package entity_crud
 
 import (
-	"git.sxidc.com/go-framework/baize/framework/core/api"
 	"git.sxidc.com/go-framework/baize/framework/core/api/response"
 	"git.sxidc.com/go-framework/baize/framework/gateway"
 	"git.sxidc.com/go-tools/utils/http_client"
@@ -83,8 +82,8 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 		builder.PostRouteWithTenantIDAndCreateUserInfo("/"+simple.ServiceShortName+domainPath+"/create",
 			func(requestBuilder *gateway.RequestBuilder) {
 				if createOptions.responseSuccessCallback != nil {
-					requestBuilder.ResponseSuccessCallback(func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any) {
-						err := createOptions.responseSuccessCallback(c, historyRequests, resultMap)
+					requestBuilder.ResponseSuccessCallback(func(c *gateway.RequestBuilderContext) {
+						err := createOptions.responseSuccessCallback(c)
 						if err != nil {
 							requestBuilder.ResponseError(err)
 							return
@@ -93,8 +92,8 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 				}
 
 				if createOptions.responseErrorCallback != nil {
-					requestBuilder.ResponseErrorCallback(func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any, err error) {
-						retErr := createOptions.responseErrorCallback(c, historyRequests, resultMap, err)
+					requestBuilder.ResponseErrorCallback(func(c *gateway.RequestBuilderContext, err error) {
+						retErr := createOptions.responseErrorCallback(c, err)
 						if retErr != nil {
 							requestBuilder.ResponseError(retErr)
 							return
@@ -108,17 +107,17 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 							Url: simple.ServiceVersionedUrl + domainPath + "/create",
 						},
 						gateway.WithBeforeRequestCallback(
-							func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any) error {
+							func(c *gateway.RequestBuilderContext) error {
 								if createOptions.beforeBuilderCallback != nil {
-									return createOptions.beforeBuilderCallback(c, historyRequests, resultMap)
+									return createOptions.beforeBuilderCallback(c)
 								}
 
 								return nil
 							}),
 						gateway.WithRequestResponseCallback(
-							func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any, response *http_client.Response) error {
+							func(c *gateway.RequestBuilderContext, response *http_client.Response) error {
 								if createOptions.afterBuilderCallback != nil {
-									err := createOptions.afterBuilderCallback(c, historyRequests, resultMap)
+									err := createOptions.afterBuilderCallback(c)
 									if err != nil {
 										return err
 									}
@@ -126,8 +125,8 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 
 								return nil
 							})).
-					ResponseErrorCallback(func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any, err error) {
-						response.SendIDResponse(requestBuilder.Context(), http.StatusOK, "", err)
+					ResponseErrorCallback(func(c *gateway.RequestBuilderContext, err error) {
+						response.SendIDResponse(c.ApiContext(), http.StatusOK, "", err)
 					}).
 					Request()
 			}, createMiddlewares...)
@@ -140,8 +139,8 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 		builder.DeleteRouteWithDeleteUserInfo("/"+simple.ServiceShortName+domainPath+"/delete",
 			func(requestBuilder *gateway.RequestBuilder) {
 				if deleteOptions.responseSuccessCallback != nil {
-					requestBuilder.ResponseSuccessCallback(func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any) {
-						err := deleteOptions.responseSuccessCallback(c, historyRequests, resultMap)
+					requestBuilder.ResponseSuccessCallback(func(c *gateway.RequestBuilderContext) {
+						err := deleteOptions.responseSuccessCallback(c)
 						if err != nil {
 							requestBuilder.ResponseError(err)
 							return
@@ -150,8 +149,8 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 				}
 
 				if deleteOptions.responseErrorCallback != nil {
-					requestBuilder.ResponseErrorCallback(func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any, err error) {
-						retErr := deleteOptions.responseErrorCallback(c, historyRequests, resultMap, err)
+					requestBuilder.ResponseErrorCallback(func(c *gateway.RequestBuilderContext, err error) {
+						retErr := deleteOptions.responseErrorCallback(c, err)
 						if retErr != nil {
 							requestBuilder.ResponseError(retErr)
 							return
@@ -165,9 +164,9 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 							Url: simple.ServiceVersionedUrl + domainPath + "/delete",
 						},
 						gateway.WithBeforeRequestCallback(
-							func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any) error {
+							func(c *gateway.RequestBuilderContext) error {
 								if deleteOptions.beforeBuilderCallback != nil {
-									err := deleteOptions.beforeBuilderCallback(c, historyRequests, resultMap)
+									err := deleteOptions.beforeBuilderCallback(c)
 									if err != nil {
 										return err
 									}
@@ -176,9 +175,9 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 								return nil
 							}),
 						gateway.WithRequestResponseCallback(
-							func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any, response *http_client.Response) error {
+							func(c *gateway.RequestBuilderContext, response *http_client.Response) error {
 								if deleteOptions.afterBuilderCallback != nil {
-									err := deleteOptions.afterBuilderCallback(c, historyRequests, resultMap)
+									err := deleteOptions.afterBuilderCallback(c)
 									if err != nil {
 										return err
 									}
@@ -197,8 +196,8 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 		builder.PutRouteWithUpdateUserInfo("/"+simple.ServiceShortName+domainPath+"/update",
 			func(requestBuilder *gateway.RequestBuilder) {
 				if updateOptions.responseSuccessCallback != nil {
-					requestBuilder.ResponseSuccessCallback(func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any) {
-						err := updateOptions.responseSuccessCallback(c, historyRequests, resultMap)
+					requestBuilder.ResponseSuccessCallback(func(c *gateway.RequestBuilderContext) {
+						err := updateOptions.responseSuccessCallback(c)
 						if err != nil {
 							requestBuilder.ResponseError(err)
 							return
@@ -207,8 +206,8 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 				}
 
 				if updateOptions.responseErrorCallback != nil {
-					requestBuilder.ResponseErrorCallback(func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any, err error) {
-						retErr := updateOptions.responseErrorCallback(c, historyRequests, resultMap, err)
+					requestBuilder.ResponseErrorCallback(func(c *gateway.RequestBuilderContext, err error) {
+						retErr := updateOptions.responseErrorCallback(c, err)
 						if retErr != nil {
 							requestBuilder.ResponseError(retErr)
 							return
@@ -221,9 +220,9 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 						&gateway.PutRequest{
 							Url: simple.ServiceVersionedUrl + domainPath + "/update",
 						},
-						gateway.WithBeforeRequestCallback(func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any) error {
+						gateway.WithBeforeRequestCallback(func(c *gateway.RequestBuilderContext) error {
 							if updateOptions.beforeBuilderCallback != nil {
-								err := updateOptions.beforeBuilderCallback(c, historyRequests, resultMap)
+								err := updateOptions.beforeBuilderCallback(c)
 								if err != nil {
 									return err
 								}
@@ -232,9 +231,9 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 							return nil
 						}),
 						gateway.WithRequestResponseCallback(
-							func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any, response *http_client.Response) error {
+							func(c *gateway.RequestBuilderContext, response *http_client.Response) error {
 								if updateOptions.afterBuilderCallback != nil {
-									err := updateOptions.afterBuilderCallback(c, historyRequests, resultMap)
+									err := updateOptions.afterBuilderCallback(c)
 									if err != nil {
 										return err
 									}
@@ -253,8 +252,8 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 		builder.GetRouteWithTenantID("/"+simple.ServiceShortName+domainPath+"/query",
 			func(requestBuilder *gateway.RequestBuilder) {
 				if queryOptions.responseSuccessCallback != nil {
-					requestBuilder.ResponseSuccessCallback(func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any) {
-						err := queryOptions.responseSuccessCallback(c, historyRequests, resultMap)
+					requestBuilder.ResponseSuccessCallback(func(c *gateway.RequestBuilderContext) {
+						err := queryOptions.responseSuccessCallback(c)
 						if err != nil {
 							requestBuilder.ResponseError(err)
 							return
@@ -263,8 +262,8 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 				}
 
 				if queryOptions.responseErrorCallback != nil {
-					requestBuilder.ResponseErrorCallback(func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any, err error) {
-						retErr := queryOptions.responseErrorCallback(c, historyRequests, resultMap, err)
+					requestBuilder.ResponseErrorCallback(func(c *gateway.RequestBuilderContext, err error) {
+						retErr := queryOptions.responseErrorCallback(c, err)
 						if retErr != nil {
 							requestBuilder.ResponseError(retErr)
 							return
@@ -277,9 +276,9 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 						&gateway.GetRequest{
 							Url: simple.ServiceVersionedUrl + domainPath + "/query",
 						},
-						gateway.WithBeforeRequestCallback(func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any) error {
+						gateway.WithBeforeRequestCallback(func(c *gateway.RequestBuilderContext) error {
 							if queryOptions.beforeBuilderCallback != nil {
-								err := queryOptions.beforeBuilderCallback(c, historyRequests, resultMap)
+								err := queryOptions.beforeBuilderCallback(c)
 								if err != nil {
 									return err
 								}
@@ -288,9 +287,9 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 							return nil
 						}),
 						gateway.WithRequestResponseCallback(
-							func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any, response *http_client.Response) error {
+							func(c *gateway.RequestBuilderContext, response *http_client.Response) error {
 								if queryOptions.afterBuilderCallback != nil {
-									err := queryOptions.afterBuilderCallback(c, historyRequests, resultMap)
+									err := queryOptions.afterBuilderCallback(c)
 									if err != nil {
 										return err
 									}
@@ -309,8 +308,8 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 		builder.GetRoute("/"+simple.ServiceShortName+domainPath+"/get",
 			func(requestBuilder *gateway.RequestBuilder) {
 				if getByIDOptions.responseSuccessCallback != nil {
-					requestBuilder.ResponseSuccessCallback(func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any) {
-						err := getByIDOptions.responseSuccessCallback(c, historyRequests, resultMap)
+					requestBuilder.ResponseSuccessCallback(func(c *gateway.RequestBuilderContext) {
+						err := getByIDOptions.responseSuccessCallback(c)
 						if err != nil {
 							requestBuilder.ResponseError(err)
 							return
@@ -319,8 +318,8 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 				}
 
 				if getByIDOptions.responseErrorCallback != nil {
-					requestBuilder.ResponseErrorCallback(func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any, err error) {
-						retErr := getByIDOptions.responseErrorCallback(c, historyRequests, resultMap, err)
+					requestBuilder.ResponseErrorCallback(func(c *gateway.RequestBuilderContext, err error) {
+						retErr := getByIDOptions.responseErrorCallback(c, err)
 						if retErr != nil {
 							requestBuilder.ResponseError(retErr)
 							return
@@ -334,9 +333,9 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 							Url: simple.ServiceVersionedUrl + domainPath + "/get",
 						},
 						gateway.WithBeforeRequestCallback(
-							func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any) error {
+							func(c *gateway.RequestBuilderContext) error {
 								if getByIDOptions.beforeBuilderCallback != nil {
-									err := getByIDOptions.beforeBuilderCallback(c, historyRequests, resultMap)
+									err := getByIDOptions.beforeBuilderCallback(c)
 									if err != nil {
 										return err
 									}
@@ -345,9 +344,9 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 								return nil
 							}),
 						gateway.WithRequestResponseCallback(
-							func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any, response *http_client.Response) error {
+							func(c *gateway.RequestBuilderContext, response *http_client.Response) error {
 								if getByIDOptions.afterBuilderCallback != nil {
-									err := getByIDOptions.afterBuilderCallback(c, historyRequests, resultMap)
+									err := getByIDOptions.afterBuilderCallback(c)
 									if err != nil {
 										return err
 									}
@@ -360,8 +359,8 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 	}
 }
 
-type RequestBuilderCallback func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any) error
-type RequestBuilderErrorCallback func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any, err error) error
+type RequestBuilderCallback func(c *gateway.RequestBuilderContext) error
+type RequestBuilderErrorCallback func(c *gateway.RequestBuilderContext, err error) error
 
 type GlobalOption func(options *GlobalOptions)
 type CreateOption func(options *CreateOptions)

+ 10 - 11
convenient/gwtools/pass_through/pass_through.go

@@ -1,7 +1,6 @@
 package pass_through
 
 import (
-	"git.sxidc.com/go-framework/baize/framework/core/api"
 	"git.sxidc.com/go-framework/baize/framework/gateway"
 	"git.sxidc.com/go-tools/utils/http_client"
 	"git.sxidc.com/go-tools/utils/strutils"
@@ -490,8 +489,8 @@ func (params *Simple) passThrough(builder *gateway.Builder, httpMethod string, o
 	builder.AddRoute(httpMethod, params.RelativePath,
 		func(requestBuilder *gateway.RequestBuilder) {
 			if options.responseSuccessCallback != nil {
-				requestBuilder.ResponseSuccessCallback(func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any) {
-					err := options.responseSuccessCallback(c, historyRequests, resultMap)
+				requestBuilder.ResponseSuccessCallback(func(c *gateway.RequestBuilderContext) {
+					err := options.responseSuccessCallback(c)
 					if err != nil {
 						requestBuilder.ResponseError(err)
 						return
@@ -500,8 +499,8 @@ func (params *Simple) passThrough(builder *gateway.Builder, httpMethod string, o
 			}
 
 			if options.responseErrorCallback != nil {
-				requestBuilder.ResponseErrorCallback(func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any, err error) {
-					retErr := options.responseErrorCallback(c, historyRequests, resultMap, err)
+				requestBuilder.ResponseErrorCallback(func(c *gateway.RequestBuilderContext, err error) {
+					retErr := options.responseErrorCallback(c, err)
 					if retErr != nil {
 						requestBuilder.ResponseError(retErr)
 						return
@@ -532,8 +531,8 @@ func (params *Simple) passThrough(builder *gateway.Builder, httpMethod string, o
 
 			if options.beforeRequestCallback != nil {
 				requestOptions = append(requestOptions, gateway.WithBeforeRequestCallback(
-					func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any) error {
-						err := options.beforeRequestCallback(c, historyRequests, resultMap)
+					func(c *gateway.RequestBuilderContext) error {
+						err := options.beforeRequestCallback(c)
 						if err != nil {
 							return err
 						}
@@ -544,8 +543,8 @@ func (params *Simple) passThrough(builder *gateway.Builder, httpMethod string, o
 
 			if options.afterRequestCallback != nil {
 				requestOptions = append(requestOptions, gateway.WithRequestResponseCallback(
-					func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any, response *http_client.Response) error {
-						err := options.afterRequestCallback(c, historyRequests, resultMap)
+					func(c *gateway.RequestBuilderContext, response *http_client.Response) error {
+						err := options.afterRequestCallback(c)
 						if err != nil {
 							return err
 						}
@@ -579,8 +578,8 @@ func (params *Simple) passThrough(builder *gateway.Builder, httpMethod string, o
 		}, options.middlewares...)
 }
 
-type RequestBuilderCallback func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any) error
-type RequestBuilderErrCallback func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any, err error) error
+type RequestBuilderCallback func(c *gateway.RequestBuilderContext) error
+type RequestBuilderErrCallback func(c *gateway.RequestBuilderContext, err error) error
 
 type Option func(options *Options)
 

+ 26 - 27
convenient/gwtools/value_object_crud/value_object_crud.go

@@ -1,7 +1,6 @@
 package value_object_crud
 
 import (
-	"git.sxidc.com/go-framework/baize/framework/core/api"
 	"git.sxidc.com/go-framework/baize/framework/gateway"
 	"git.sxidc.com/go-tools/utils/http_client"
 	"git.sxidc.com/go-tools/utils/template"
@@ -69,8 +68,8 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 		builder.PostRouteWithTenantIDAndCreateUserID("/"+simple.ServiceShortName+domainPath+"/create",
 			func(requestBuilder *gateway.RequestBuilder) {
 				if createOptions.responseSuccessCallback != nil {
-					requestBuilder.ResponseSuccessCallback(func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any) {
-						err := createOptions.responseSuccessCallback(c, historyRequests, resultMap)
+					requestBuilder.ResponseSuccessCallback(func(c *gateway.RequestBuilderContext) {
+						err := createOptions.responseSuccessCallback(c)
 						if err != nil {
 							requestBuilder.ResponseError(err)
 							return
@@ -79,8 +78,8 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 				}
 
 				if createOptions.responseErrorCallback != nil {
-					requestBuilder.ResponseErrorCallback(func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any, err error) {
-						retErr := createOptions.responseErrorCallback(c, historyRequests, resultMap, err)
+					requestBuilder.ResponseErrorCallback(func(c *gateway.RequestBuilderContext, err error) {
+						retErr := createOptions.responseErrorCallback(c, err)
 						if retErr != nil {
 							requestBuilder.ResponseError(retErr)
 							return
@@ -94,9 +93,9 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 							Url: simple.ServiceVersionedUrl + domainPath + "/create",
 						},
 						gateway.WithBeforeRequestCallback(
-							func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any) error {
+							func(c *gateway.RequestBuilderContext) error {
 								if createOptions.beforeBuilderCallback != nil {
-									err := createOptions.beforeBuilderCallback(c, historyRequests, resultMap)
+									err := createOptions.beforeBuilderCallback(c)
 									if err != nil {
 										return err
 									}
@@ -105,9 +104,9 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 								return nil
 							}),
 						gateway.WithRequestResponseCallback(
-							func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any, response *http_client.Response) error {
+							func(c *gateway.RequestBuilderContext, response *http_client.Response) error {
 								if createOptions.afterBuilderCallback != nil {
-									err := createOptions.afterBuilderCallback(c, historyRequests, resultMap)
+									err := createOptions.afterBuilderCallback(c)
 									if err != nil {
 										return err
 									}
@@ -126,8 +125,8 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 		builder.PostRoute("/"+simple.ServiceShortName+domainPath+"/delete",
 			func(requestBuilder *gateway.RequestBuilder) {
 				if deleteOptions.responseSuccessCallback != nil {
-					requestBuilder.ResponseSuccessCallback(func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any) {
-						err := deleteOptions.responseSuccessCallback(c, historyRequests, resultMap)
+					requestBuilder.ResponseSuccessCallback(func(c *gateway.RequestBuilderContext) {
+						err := deleteOptions.responseSuccessCallback(c)
 						if err != nil {
 							requestBuilder.ResponseError(err)
 							return
@@ -136,8 +135,8 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 				}
 
 				if deleteOptions.responseErrorCallback != nil {
-					requestBuilder.ResponseErrorCallback(func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any, err error) {
-						retErr := deleteOptions.responseErrorCallback(c, historyRequests, resultMap, err)
+					requestBuilder.ResponseErrorCallback(func(c *gateway.RequestBuilderContext, err error) {
+						retErr := deleteOptions.responseErrorCallback(c, err)
 						if retErr != nil {
 							requestBuilder.ResponseError(retErr)
 							return
@@ -151,9 +150,9 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 							Url: simple.ServiceVersionedUrl + domainPath + "/delete",
 						},
 						gateway.WithBeforeRequestCallback(
-							func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any) error {
+							func(c *gateway.RequestBuilderContext) error {
 								if deleteOptions.beforeBuilderCallback != nil {
-									err := deleteOptions.beforeBuilderCallback(c, historyRequests, resultMap)
+									err := deleteOptions.beforeBuilderCallback(c)
 									if err != nil {
 										return err
 									}
@@ -162,9 +161,9 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 								return nil
 							}),
 						gateway.WithRequestResponseCallback(
-							func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any, response *http_client.Response) error {
+							func(c *gateway.RequestBuilderContext, response *http_client.Response) error {
 								if deleteOptions.afterBuilderCallback != nil {
-									err := deleteOptions.afterBuilderCallback(c, historyRequests, resultMap)
+									err := deleteOptions.afterBuilderCallback(c)
 									if err != nil {
 										return err
 									}
@@ -183,8 +182,8 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 		builder.GetRouteWithTenantID("/"+simple.ServiceShortName+domainPath+"/query",
 			func(requestBuilder *gateway.RequestBuilder) {
 				if queryOptions.responseSuccessCallback != nil {
-					requestBuilder.ResponseSuccessCallback(func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any) {
-						err := queryOptions.responseSuccessCallback(c, historyRequests, resultMap)
+					requestBuilder.ResponseSuccessCallback(func(c *gateway.RequestBuilderContext) {
+						err := queryOptions.responseSuccessCallback(c)
 						if err != nil {
 							requestBuilder.ResponseError(err)
 							return
@@ -193,8 +192,8 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 				}
 
 				if queryOptions.responseErrorCallback != nil {
-					requestBuilder.ResponseErrorCallback(func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any, err error) {
-						retErr := queryOptions.responseErrorCallback(c, historyRequests, resultMap, err)
+					requestBuilder.ResponseErrorCallback(func(c *gateway.RequestBuilderContext, err error) {
+						retErr := queryOptions.responseErrorCallback(c, err)
 						if retErr != nil {
 							requestBuilder.ResponseError(retErr)
 							return
@@ -208,9 +207,9 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 							Url: simple.ServiceVersionedUrl + domainPath + "/query",
 						},
 						gateway.WithBeforeRequestCallback(
-							func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any) error {
+							func(c *gateway.RequestBuilderContext) error {
 								if queryOptions.beforeBuilderCallback != nil {
-									err := queryOptions.beforeBuilderCallback(c, historyRequests, resultMap)
+									err := queryOptions.beforeBuilderCallback(c)
 									if err != nil {
 										return err
 									}
@@ -219,9 +218,9 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 								return nil
 							}),
 						gateway.WithRequestResponseCallback(
-							func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any, response *http_client.Response) error {
+							func(c *gateway.RequestBuilderContext, response *http_client.Response) error {
 								if queryOptions.afterBuilderCallback != nil {
-									err := queryOptions.afterBuilderCallback(c, historyRequests, resultMap)
+									err := queryOptions.afterBuilderCallback(c)
 									if err != nil {
 										return err
 									}
@@ -234,8 +233,8 @@ func (simple *Simple) bind(builder *gateway.Builder) {
 	}
 }
 
-type RequestBuilderCallback func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any) error
-type RequestBuilderErrorCallback func(c *api.Context, historyRequests []gateway.Request, resultMap map[string]any, err error) error
+type RequestBuilderCallback func(c *gateway.RequestBuilderContext) error
+type RequestBuilderErrorCallback func(c *gateway.RequestBuilderContext, err error) error
 
 type GlobalOption func(options *GlobalOptions)
 type CreateOption func(options *CreateOptions)

+ 11 - 11
framework/gateway/common.go

@@ -5,7 +5,7 @@ import (
 )
 
 func AddJsonBodyTenantIDAndUserInfo(requestBuilder *RequestBuilder, tenantIDParamsName string, userIDParamsName string, operatorUserNameParamsName string) error {
-	jsonBody, err := requestBuilder.c.GetJsonBody()
+	jsonBody, err := requestBuilder.c.apiContext.GetJsonBody()
 	if err != nil {
 		return err
 	}
@@ -13,7 +13,7 @@ func AddJsonBodyTenantIDAndUserInfo(requestBuilder *RequestBuilder, tenantIDPara
 	if strutils.IsStringNotEmpty(tenantIDParamsName) {
 		tenantID := jsonBody.Get(tenantIDParamsName)
 		if tenantID == nil {
-			tenantInfo := requestBuilder.c.GetTenantInfo()
+			tenantInfo := requestBuilder.c.apiContext.GetTenantInfo()
 
 			if tenantInfo != nil {
 				jsonBody.Set(tenantIDParamsName, tenantInfo.GetID())
@@ -26,7 +26,7 @@ func AddJsonBodyTenantIDAndUserInfo(requestBuilder *RequestBuilder, tenantIDPara
 	if strutils.IsStringNotEmpty(userIDParamsName) {
 		userID := jsonBody.Get(userIDParamsName)
 		if userID == nil {
-			userInfo := requestBuilder.c.GetUserInfo()
+			userInfo := requestBuilder.c.apiContext.GetUserInfo()
 
 			if userInfo != nil {
 				jsonBody.Set(userIDParamsName, userInfo.GetID())
@@ -39,7 +39,7 @@ func AddJsonBodyTenantIDAndUserInfo(requestBuilder *RequestBuilder, tenantIDPara
 	if strutils.IsStringNotEmpty(operatorUserNameParamsName) {
 		operatorUserName := jsonBody.Get(operatorUserNameParamsName)
 		if operatorUserName == nil {
-			userInfo := requestBuilder.c.GetUserInfo()
+			userInfo := requestBuilder.c.apiContext.GetUserInfo()
 
 			if userInfo != nil {
 				jsonBody.Set(operatorUserNameParamsName, userInfo.GetUserName())
@@ -53,26 +53,26 @@ func AddJsonBodyTenantIDAndUserInfo(requestBuilder *RequestBuilder, tenantIDPara
 }
 
 func AddQueryParamsTenantIDAndUserInfo(requestBuilder *RequestBuilder, tenantIDParamsName string, userIDParamsName string, operatorUserNameParamsName string) error {
-	queryParams := requestBuilder.c.GetQueryParams()
+	queryParams := requestBuilder.c.apiContext.GetQueryParams()
 
-	if requestBuilder.c.GetTenantInfo() != nil && strutils.IsStringNotEmpty(tenantIDParamsName) {
+	if requestBuilder.c.apiContext.GetTenantInfo() != nil && strutils.IsStringNotEmpty(tenantIDParamsName) {
 		tenantID := queryParams.Get(tenantIDParamsName)
 		if strutils.IsStringEmpty(tenantID) {
-			queryParams.Set(tenantIDParamsName, requestBuilder.c.GetTenantInfo().GetID())
+			queryParams.Set(tenantIDParamsName, requestBuilder.c.apiContext.GetTenantInfo().GetID())
 		}
 	}
 
-	if requestBuilder.c.GetUserInfo() != nil && strutils.IsStringNotEmpty(userIDParamsName) {
+	if requestBuilder.c.apiContext.GetUserInfo() != nil && strutils.IsStringNotEmpty(userIDParamsName) {
 		userID := queryParams.Get(userIDParamsName)
 		if strutils.IsStringEmpty(userID) {
-			queryParams.Set(userIDParamsName, requestBuilder.c.GetUserInfo().GetID())
+			queryParams.Set(userIDParamsName, requestBuilder.c.apiContext.GetUserInfo().GetID())
 		}
 	}
 
-	if requestBuilder.c.GetUserInfo() != nil && strutils.IsStringNotEmpty(operatorUserNameParamsName) {
+	if requestBuilder.c.apiContext.GetUserInfo() != nil && strutils.IsStringNotEmpty(operatorUserNameParamsName) {
 		operatorUserName := queryParams.Get(operatorUserNameParamsName)
 		if strutils.IsStringEmpty(operatorUserName) {
-			queryParams.Set(operatorUserNameParamsName, requestBuilder.c.GetUserInfo().GetUserName())
+			queryParams.Set(operatorUserNameParamsName, requestBuilder.c.apiContext.GetUserInfo().GetUserName())
 		}
 	}
 

+ 66 - 30
framework/gateway/request_builder.go

@@ -7,16 +7,16 @@ import (
 )
 
 // ResponseSuccessCallback 网关API成功响应回调
-type ResponseSuccessCallback func(c *api.Context, historyRequests []Request, resultMap map[string]any)
+type ResponseSuccessCallback func(c *RequestBuilderContext)
 
 // ResponseErrorCallback 网关API错误响应回调
-type ResponseErrorCallback func(c *api.Context, historyRequests []Request, resultMap map[string]any, err error)
+type ResponseErrorCallback func(c *RequestBuilderContext, err error)
 
 // BeforeRequestCallback 请求发送前的回调
-type BeforeRequestCallback func(c *api.Context, historyRequests []Request, resultMap map[string]any) error
+type BeforeRequestCallback func(c *RequestBuilderContext) error
 
 // RequestResponseCallback 请求响应回调
-type RequestResponseCallback func(c *api.Context, historyRequests []Request, resultMap map[string]any, response *http_client.Response) error
+type RequestResponseCallback func(c *RequestBuilderContext, response *http_client.Response) error
 
 type RequestOption func(options *RequestOptions)
 
@@ -39,40 +39,76 @@ func WithRequestResponseCallback(callback RequestResponseCallback) RequestOption
 	}
 }
 
-// RequestBuilder 请求构建器
-type RequestBuilder struct {
-	c               *api.Context
+// RequestBuilderContext 请求构建器上下文
+type RequestBuilderContext struct {
+	apiContext      *api.Context
 	historyRequests []Request
 	resultMap       map[string]any
-
-	httpRequest *http_client.Request
-	params      *requestBuilderParams
 }
 
-func newRequestBuilder(c *api.Context, httpRequest *http_client.Request) *RequestBuilder {
-	return &RequestBuilder{
-		c:               c,
+func newRequestBuilderContext(c *api.Context) *RequestBuilderContext {
+	return &RequestBuilderContext{
+		apiContext:      c,
 		historyRequests: make([]Request, 0),
 		resultMap:       make(map[string]any),
-		httpRequest:     httpRequest,
-		params:          newRequestBuilderParams(),
 	}
 }
 
-// Context 获取上下文
+// ApiContext 获取Api上下文
 // 参数: 无
 // 返回值:
 // - 上下文
-func (builder *RequestBuilder) Context() *api.Context {
-	return builder.c
+func (c *RequestBuilderContext) ApiContext() *api.Context {
+	return c.apiContext
 }
 
 // HistoryRequests 获取历史请求(包含响应)
 // 参数: 无
 // 返回值:
 // - 历史请求
-func (builder *RequestBuilder) HistoryRequests() []Request {
-	return builder.historyRequests
+func (c *RequestBuilderContext) HistoryRequests() []Request {
+	return c.historyRequests
+}
+
+// GetResultMapValue 获取结果Map的值
+// 参数:
+// - key: 键
+// 返回值:
+// - 值
+func (c *RequestBuilderContext) GetResultMapValue(key string) any {
+	return c.resultMap[key]
+}
+
+// SetResultMapValue 设置结果Map的值
+// 参数:
+// - key: 键
+// - 值
+// 返回值: 无
+func (c *RequestBuilderContext) SetResultMapValue(key string, value any) {
+	c.resultMap[key] = value
+}
+
+// RequestBuilder 请求构建器
+type RequestBuilder struct {
+	c           *RequestBuilderContext
+	httpRequest *http_client.Request
+	params      *requestBuilderParams
+}
+
+func newRequestBuilder(c *api.Context, httpRequest *http_client.Request) *RequestBuilder {
+	return &RequestBuilder{
+		c:           newRequestBuilderContext(c),
+		httpRequest: httpRequest,
+		params:      newRequestBuilderParams(),
+	}
+}
+
+// ApiContext 获取Api上下文
+// 参数: 无
+// 返回值:
+// - 上下文
+func (builder *RequestBuilder) ApiContext() *api.Context {
+	return builder.c.apiContext
 }
 
 // Post 定义POST请求
@@ -143,31 +179,31 @@ func (builder *RequestBuilder) Request() {
 
 	for _, requestItem := range builder.params.requestItems {
 		if requestItem.options.beforeRequestCallback != nil {
-			err := requestItem.options.beforeRequestCallback(builder.c, builder.historyRequests, builder.resultMap)
+			err := requestItem.options.beforeRequestCallback(builder.c)
 			if err != nil {
-				builder.params.responseErrorCallback(builder.c, builder.historyRequests, builder.resultMap, errors.New(err.Error()))
+				builder.params.responseErrorCallback(builder.c, errors.New(err.Error()))
 				return
 			}
 		}
 
-		requestWithResponse, err := requestItem.builderRequest.Request(builder.c, httpRequest)
+		requestWithResponse, err := requestItem.builderRequest.Request(builder.c.apiContext, httpRequest)
 		if err != nil {
-			builder.params.responseErrorCallback(builder.c, builder.historyRequests, builder.resultMap, errors.New(err.Error()))
+			builder.params.responseErrorCallback(builder.c, errors.New(err.Error()))
 			return
 		}
 
-		builder.historyRequests = append(builder.historyRequests, requestWithResponse)
+		builder.c.historyRequests = append(builder.c.historyRequests, requestWithResponse)
 
 		if requestItem.options.requestResponseCallback != nil {
-			err := requestItem.options.requestResponseCallback(builder.c, builder.historyRequests, builder.resultMap, requestWithResponse.Response())
+			err := requestItem.options.requestResponseCallback(builder.c, requestWithResponse.Response())
 			if err != nil {
-				builder.params.responseErrorCallback(builder.c, builder.historyRequests, builder.resultMap, errors.New(err.Error()))
+				builder.params.responseErrorCallback(builder.c, errors.New(err.Error()))
 				return
 			}
 		}
 	}
 
-	builder.params.responseSuccessCallback(builder.c, builder.historyRequests, builder.resultMap)
+	builder.params.responseSuccessCallback(builder.c)
 }
 
 // ResponseError 利用网关API错误响应回调发送网关API响应
@@ -175,14 +211,14 @@ func (builder *RequestBuilder) Request() {
 // - 错误
 // 返回值: 无
 func (builder *RequestBuilder) ResponseError(err error) {
-	builder.params.responseErrorCallback(builder.c, builder.historyRequests, builder.resultMap, err)
+	builder.params.responseErrorCallback(builder.c, err)
 }
 
 // ResponseSuccess 利用网关API成功响应回调发送网关API响应
 // 参数: 无
 // 返回值: 无
 func (builder *RequestBuilder) ResponseSuccess() {
-	builder.params.responseSuccessCallback(builder.c, builder.historyRequests, builder.resultMap)
+	builder.params.responseSuccessCallback(builder.c)
 }
 
 func (builder *RequestBuilder) request(builderRequest Request, opts ...RequestOption) *RequestBuilder {

+ 8 - 9
framework/gateway/request_builder_params.go

@@ -1,7 +1,6 @@
 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"
@@ -16,21 +15,21 @@ type requestBuilderParams struct {
 func newRequestBuilderParams() *requestBuilderParams {
 	return &requestBuilderParams{
 		requestItems: make([]*builderRequestItem, 0),
-		responseSuccessCallback: func(c *api.Context, historyRequests []Request, resultMap map[string]any) {
-			c.Status(http.StatusOK)
+		responseSuccessCallback: func(c *RequestBuilderContext) {
+			c.apiContext.Status(http.StatusOK)
 
-			if historyRequests != nil && len(historyRequests) != 0 {
-				_, err := c.Writer.Write(historyRequests[len(historyRequests)-1].Response().Body())
+			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.AbortWithStatus(http.StatusInternalServerError)
+					c.apiContext.AbortWithStatus(http.StatusInternalServerError)
 					return
 				}
 			}
 
-			c.Writer.Flush()
+			c.apiContext.Writer.Flush()
 		},
-		responseErrorCallback: func(c *api.Context, historyRequests []Request, resultMap map[string]any, err error) {
+		responseErrorCallback: func(c *RequestBuilderContext, err error) {
 			if err == nil {
 				return
 			}
@@ -42,7 +41,7 @@ func newRequestBuilderParams() *requestBuilderParams {
 			resp["errCode"] = http.StatusOK
 			resp["msg"] = err.Error()
 
-			c.JSON(http.StatusOK, resp)
+			c.apiContext.JSON(http.StatusOK, resp)
 		},
 	}
 }