소스 검색

修改请求

yjp 1 년 전
부모
커밋
240024d2be

+ 0 - 21
convenient/domain_gateway/configuration.go

@@ -1,21 +0,0 @@
-package domain_gateway
-
-import (
-	"git.sxidc.com/go-framework/baize/convenient/gwtools"
-	"git.sxidc.com/go-framework/baize/framework/gateway"
-	"net/http"
-)
-
-func ConfigurationGateway(serviceVersionedUrl string, builder *gateway.Builder) {
-	gwtools.ValueObjectCRUD(builder, &gwtools.ValueObjectCRUDParams{
-		ServiceVersionedUrl: serviceVersionedUrl,
-		DomainCamelName:     "Configuration",
-	}, gwtools.WithValueObjectCRUDDisableQuery())
-
-	builder.
-		Url(http.MethodGet, "/configuration/values").
-		Get(&gateway.GetRequest{
-			Url: serviceVersionedUrl + "/configuration/values",
-		}, nil).
-		Build()
-}

+ 169 - 0
convenient/domain_gateway/configuration/configuration.go

@@ -0,0 +1,169 @@
+package configuration
+
+import (
+	"git.sxidc.com/go-framework/baize/framework/core/api"
+	"git.sxidc.com/go-framework/baize/framework/gateway"
+	"git.sxidc.com/go-tools/utils/strutils"
+	"git.sxidc.com/service-supports/fserr"
+	"net/http"
+	"net/url"
+	"sync"
+)
+
+type Option func(options *Options)
+
+type Options struct {
+	serviceApiVersion string
+}
+
+func WithServiceApiVersion(serviceApiVersion string) Option {
+	return func(options *Options) {
+		options.serviceApiVersion = serviceApiVersion
+	}
+}
+
+var serviceBaseUrlMap sync.Map
+
+func RegisterService(serviceShortName string, baseUrl string) {
+	serviceBaseUrlMap.Store(serviceShortName, baseUrl)
+}
+
+func BuildGateway(builder *gateway.Builder, opts ...Option) {
+	options := new(Options)
+
+	for _, opt := range opts {
+		opt(options)
+	}
+
+	// 创建
+	builder.
+		Url(http.MethodPost, "/configuration/create").
+		Post(gateway.NewPostRequest("",
+			gateway.PostRequestWithUrlTransferFunc(
+				func(c *api.Context, _ string, historyRequest []gateway.BuilderRequest, resultMap map[string]any) (string, error) {
+					jsonBody, err := c.GetJsonBody()
+					if err != nil {
+						return "", err
+					}
+
+					serviceShortName, ok := jsonBody.Get("serviceShortName").(string)
+					if !ok {
+						return "", fserr.New("没有传递服务名缩写或服务名缩写不是string类型")
+					}
+
+					jsonBody.Delete("serviceShortName")
+
+					serviceBaseUrl, loaded := serviceBaseUrlMap.Load(serviceShortName)
+					if !loaded {
+						return "", fserr.New("没有注册对应的服务: " + serviceShortName)
+					}
+
+					var serviceUrl string
+
+					if strutils.IsStringEmpty(options.serviceApiVersion) {
+						innerServiceUrl, err := url.JoinPath(serviceBaseUrl.(string), serviceShortName, "/api", "/configuration/create")
+						if err != nil {
+							return "", err
+						}
+
+						serviceUrl = innerServiceUrl
+					} else {
+						innerServiceUrl, err := url.JoinPath(serviceBaseUrl.(string), serviceShortName, "/api", options.serviceApiVersion, "/configuration/create")
+						if err != nil {
+							return "", err
+						}
+
+						serviceUrl = innerServiceUrl
+					}
+
+					return serviceUrl, nil
+				})), nil).
+		Build()
+
+	// 删除
+	builder.
+		Url(http.MethodPost, "/configuration/delete").
+		Post(gateway.NewPostRequest("",
+			gateway.PostRequestWithUrlTransferFunc(
+				func(c *api.Context, _ string, historyRequest []gateway.BuilderRequest, resultMap map[string]any) (string, error) {
+					jsonBody, err := c.GetJsonBody()
+					if err != nil {
+						return "", err
+					}
+
+					serviceShortName, ok := jsonBody.Get("serviceShortName").(string)
+					if !ok {
+						return "", fserr.New("没有传递服务名缩写或服务名缩写不是string类型")
+					}
+
+					jsonBody.Delete("serviceShortName")
+
+					serviceBaseUrl, loaded := serviceBaseUrlMap.Load(serviceShortName)
+					if !loaded {
+						return "", fserr.New("没有注册对应的服务: " + serviceShortName)
+					}
+
+					var serviceUrl string
+
+					if strutils.IsStringEmpty(options.serviceApiVersion) {
+						innerServiceUrl, err := url.JoinPath(serviceBaseUrl.(string), serviceShortName, "/api", "/configuration/delete")
+						if err != nil {
+							return "", err
+						}
+
+						serviceUrl = innerServiceUrl
+					} else {
+						innerServiceUrl, err := url.JoinPath(serviceBaseUrl.(string), serviceShortName, "/api", options.serviceApiVersion, "/configuration/delete")
+						if err != nil {
+							return "", err
+						}
+
+						serviceUrl = innerServiceUrl
+					}
+
+					return serviceUrl, nil
+				})), nil).
+		Build()
+
+	// 查询
+	builder.
+		Url(http.MethodGet, "/configuration/values").
+		Get(gateway.NewGetRequest("",
+			gateway.GetRequestWithUrlTransferFunc(
+				func(c *api.Context, _ string, historyRequest []gateway.BuilderRequest, resultMap map[string]any) (string, error) {
+					queryParams := c.GetQueryParams()
+
+					serviceShortName := queryParams.Get("serviceShortName")
+					if strutils.IsStringEmpty(serviceShortName) {
+						return "", fserr.New("没有传递服务名缩写")
+					}
+
+					queryParams.Delete("serviceShortName")
+
+					serviceBaseUrl, loaded := serviceBaseUrlMap.Load(serviceShortName)
+					if !loaded {
+						return "", fserr.New("没有注册对应的服务: " + serviceShortName)
+					}
+
+					var serviceUrl string
+
+					if strutils.IsStringEmpty(options.serviceApiVersion) {
+						innerServiceUrl, err := url.JoinPath(serviceBaseUrl.(string), serviceShortName, "/api", "/configuration/values")
+						if err != nil {
+							return "", err
+						}
+
+						serviceUrl = innerServiceUrl
+					} else {
+						innerServiceUrl, err := url.JoinPath(serviceBaseUrl.(string), serviceShortName, "/api", options.serviceApiVersion, "/configuration/values")
+						if err != nil {
+							return "", err
+						}
+
+						serviceUrl = innerServiceUrl
+					}
+
+					return serviceUrl, nil
+				})), nil).
+		Build()
+}

+ 0 - 74
convenient/domain_gateway/sql_executor.go

@@ -1,74 +0,0 @@
-package domain_gateway
-
-import (
-	"git.sxidc.com/go-framework/baize/framework/core/api"
-	"git.sxidc.com/go-framework/baize/framework/gateway"
-	"git.sxidc.com/go-tools/utils/strutils"
-	"github.com/pkg/errors"
-	"net/http"
-)
-
-func SqlExecutorGateway(baseUrlNoUrlPrefix string, builder *gateway.Builder) {
-	builder.
-		Url(http.MethodPost, "/sql/execute").
-		Request(func(c *api.Context, historyRequests []gateway.BuilderRequest, resultMap map[string]any) (gateway.BuilderRequest, error) {
-			err := gateway.AddJsonBodyTenantIDAndUserID(c, "", "executorId")
-			if err != nil {
-				return nil, err
-			}
-
-			jsonBody, err := c.GetJsonBody()
-			if err != nil {
-				return nil, err
-			}
-
-			userInfo := c.GetUserInfo()
-			if userInfo == nil {
-				jsonBody.Set("executorName", "guest")
-			} else {
-				jsonBody.Set("executorName", userInfo.GetName)
-			}
-
-			urlPrefixValue := jsonBody.Get("urlPrefix")
-			if urlPrefixValue == nil {
-				return nil, errors.New("没有传递服务名")
-			}
-
-			urlPrefix, ok := urlPrefixValue.(string)
-			if !ok {
-				return nil, errors.New("服务名不是string类型")
-			}
-
-			jsonBody.Delete("urlPrefix")
-
-			return &gateway.PostRequest{
-				Url:  baseUrlNoUrlPrefix + "/" + urlPrefix + "/api/sql/execute",
-				Body: jsonBody.Map(),
-			}, nil
-		}, nil).
-		Build()
-
-	builder.
-		Url(http.MethodGet, "/sql/execute/log").
-		Request(func(c *api.Context, historyRequests []gateway.BuilderRequest, resultMap map[string]any) (gateway.BuilderRequest, error) {
-			err := gateway.AddQueryParamsTenantIDAndUserID(c, "", "executorId")
-			if err != nil {
-				return nil, err
-			}
-
-			queryParams := c.GetQueryParams()
-
-			urlPrefix := queryParams.Get("urlPrefix")
-			if strutils.IsStringEmpty(urlPrefix) {
-				return nil, errors.New("没有传递服务名")
-			}
-
-			queryParams.Delete("urlPrefix")
-
-			return &gateway.GetRequest{
-				Url:         baseUrlNoUrlPrefix + "/" + urlPrefix + "/api/sql/execute/log",
-				QueryParams: queryParams.Map(),
-			}, nil
-		}, nil).
-		Build()
-}

+ 142 - 0
convenient/domain_gateway/sql_executor/sql_executor.go

@@ -0,0 +1,142 @@
+package sql_executor
+
+import (
+	"git.sxidc.com/go-framework/baize/framework/core/api"
+	"git.sxidc.com/go-framework/baize/framework/gateway"
+	"git.sxidc.com/go-tools/utils/strutils"
+	"git.sxidc.com/service-supports/fserr"
+	"net/http"
+	"net/url"
+	"sync"
+)
+
+type Option func(options *Options)
+
+type Options struct {
+	serviceApiVersion string
+}
+
+func WithServiceApiVersion(serviceApiVersion string) Option {
+	return func(options *Options) {
+		options.serviceApiVersion = serviceApiVersion
+	}
+}
+
+var serviceBaseUrlMap sync.Map
+
+func BuildGateway(builder *gateway.Builder, opts ...Option) {
+	options := new(Options)
+
+	for _, opt := range opts {
+		opt(options)
+	}
+
+	builder.
+		Url(http.MethodPost, "/sql/execute").
+		Post(gateway.NewPostRequest("",
+			gateway.PostRequestWithUrlTransferFunc(
+				func(c *api.Context, _ string, historyRequest []gateway.BuilderRequest, resultMap map[string]any) (string, error) {
+					jsonBody, err := c.GetJsonBody()
+					if err != nil {
+						return "", err
+					}
+
+					serviceShortName, ok := jsonBody.Get("serviceShortName").(string)
+					if !ok {
+						return "", fserr.New("没有传递服务名缩写或服务名缩写不是string类型")
+					}
+
+					jsonBody.Delete("serviceShortName")
+
+					serviceBaseUrl, loaded := serviceBaseUrlMap.Load(serviceShortName)
+					if !loaded {
+						return "", fserr.New("没有注册对应的服务: " + serviceShortName)
+					}
+
+					var serviceUrl string
+
+					if strutils.IsStringEmpty(options.serviceApiVersion) {
+						innerServiceUrl, err := url.JoinPath(serviceBaseUrl.(string), serviceShortName, "/api", "/sql/execute")
+						if err != nil {
+							return "", err
+						}
+
+						serviceUrl = innerServiceUrl
+					} else {
+						innerServiceUrl, err := url.JoinPath(serviceBaseUrl.(string), serviceShortName, "/api", options.serviceApiVersion, "/sql/execute")
+						if err != nil {
+							return "", err
+						}
+
+						serviceUrl = innerServiceUrl
+					}
+
+					return serviceUrl, nil
+				}),
+			gateway.PostRequestWithBodyForm(
+				func(c *api.Context, historyRequest []gateway.BuilderRequest, resultMap map[string]any) (any, error) {
+					err := gateway.AddJsonBodyTenantIDAndUserID(c, "", "executorId")
+					if err != nil {
+						return nil, err
+					}
+
+					jsonBody, err := c.GetJsonBody()
+					if err != nil {
+						return nil, err
+					}
+
+					userInfo := c.GetUserInfo()
+					if userInfo == nil {
+						jsonBody.Set("executorName", "guest")
+					} else {
+						jsonBody.Set("executorName", userInfo.GetName)
+					}
+
+					return jsonBody.Map(), nil
+				})), nil).
+		Build()
+
+	builder.
+		Url(http.MethodGet, "/sql/execute/log").
+		Get(gateway.NewGetRequest("",
+			gateway.GetRequestWithUrlTransferFunc(
+				func(c *api.Context, _ string, historyRequest []gateway.BuilderRequest, resultMap map[string]any) (string, error) {
+					queryParams := c.GetQueryParams()
+
+					serviceShortName := queryParams.Get("serviceShortName")
+					if strutils.IsStringEmpty(serviceShortName) {
+						return "", fserr.New("没有传递服务名缩写")
+					}
+
+					queryParams.Delete("serviceShortName")
+
+					serviceBaseUrl, loaded := serviceBaseUrlMap.Load(serviceShortName)
+					if !loaded {
+						return "", fserr.New("没有注册对应的服务: " + serviceShortName)
+					}
+
+					var serviceUrl string
+
+					if strutils.IsStringEmpty(options.serviceApiVersion) {
+						innerServiceUrl, err := url.JoinPath(serviceBaseUrl.(string), serviceShortName, "/api", "/configuration/values")
+						if err != nil {
+							return "", err
+						}
+
+						serviceUrl = innerServiceUrl
+					} else {
+						innerServiceUrl, err := url.JoinPath(serviceBaseUrl.(string), serviceShortName, "/api", options.serviceApiVersion, "/configuration/values")
+						if err != nil {
+							return "", err
+						}
+
+						serviceUrl = innerServiceUrl
+					}
+
+					return serviceUrl, nil
+				}),
+			gateway.GetRequestWithQueryParamsForm(
+				gateway.FormQueryParamsWithTenantIDAndUserIDFunc("", "executorId")),
+		), nil).
+		Build()
+}

+ 15 - 49
convenient/gwtools/entity_crud.go

@@ -69,22 +69,10 @@ func (params *EntityCRUDParams) crud(builder *gateway.Builder) {
 	if !createOptions.disable {
 		builder.
 			Url(http.MethodPost, domainPath+"/create").
-			Request(func(c *api.Context, historyRequests []gateway.BuilderRequest, resultMap map[string]any) (gateway.BuilderRequest, error) {
-				err := gateway.AddJsonBodyTenantIDAndUserID(c, "tenantId", "createUserId")
-				if err != nil {
-					return nil, err
-				}
-
-				jsonBody, err := c.GetJsonBody()
-				if err != nil {
-					return nil, err
-				}
-
-				return &gateway.PostRequest{
-					Url:  params.ServiceVersionedUrl + domainPath + "/create",
-					Body: jsonBody.Map(),
-				}, nil
-			}, createOptions.requestResponseCallback).
+			Post(gateway.NewPostRequest(params.ServiceVersionedUrl+domainPath+"/create",
+				gateway.PostRequestWithBodyForm(
+					gateway.FormJsonBodyWithTenantIDAndUserIDFunc("tenantId", "createUserId"))),
+				createOptions.requestResponseCallback).
 			Build(createOptions.middlewares...)
 	}
 
@@ -92,9 +80,8 @@ func (params *EntityCRUDParams) crud(builder *gateway.Builder) {
 	if !deleteOptions.disable {
 		builder.
 			Url(http.MethodDelete, domainPath+"/delete").
-			Delete(&gateway.DeleteRequest{
-				Url: params.ServiceVersionedUrl + domainPath + "/delete",
-			}, deleteOptions.requestResponseCallback).
+			Delete(gateway.NewDeleteRequest(params.ServiceVersionedUrl+domainPath+"/delete"),
+				deleteOptions.requestResponseCallback).
 			Build(deleteOptions.middlewares...)
 	}
 
@@ -102,22 +89,10 @@ func (params *EntityCRUDParams) crud(builder *gateway.Builder) {
 	if !updateOptions.disable {
 		builder.
 			Url(http.MethodPut, domainPath+"/update").
-			Request(func(c *api.Context, historyRequests []gateway.BuilderRequest, resultMap map[string]any) (gateway.BuilderRequest, error) {
-				err := gateway.AddJsonBodyTenantIDAndUserID(c, "", "updateUserId")
-				if err != nil {
-					return nil, err
-				}
-
-				jsonBody, err := c.GetJsonBody()
-				if err != nil {
-					return nil, err
-				}
-
-				return &gateway.PutRequest{
-					Url:  params.ServiceVersionedUrl + domainPath + "/update",
-					Body: jsonBody.Map(),
-				}, nil
-			}, updateOptions.requestResponseCallback).
+			Put(gateway.NewPutRequest(params.ServiceVersionedUrl+domainPath+"/update",
+				gateway.PutRequestWithBodyForm(
+					gateway.FormJsonBodyWithTenantIDAndUserIDFunc("", "updateUserId"))),
+				updateOptions.requestResponseCallback).
 			Build(updateOptions.middlewares...)
 	}
 
@@ -125,17 +100,9 @@ func (params *EntityCRUDParams) crud(builder *gateway.Builder) {
 	if !queryOptions.disable {
 		builder.
 			Url(http.MethodGet, domainPath+"/query").
-			Request(func(c *api.Context, historyRequests []gateway.BuilderRequest, resultMap map[string]any) (gateway.BuilderRequest, error) {
-				err := gateway.AddQueryParamsTenantIDAndUserID(c, "tenantId", "")
-				if err != nil {
-					return nil, err
-				}
-
-				return &gateway.GetRequest{
-					Url:         params.ServiceVersionedUrl + domainPath + "/query",
-					QueryParams: c.GetQueryParams().Map(),
-				}, nil
-			}, queryOptions.requestResponseCallback).
+			Get(gateway.NewGetRequest(params.ServiceVersionedUrl+domainPath+"/query",
+				gateway.GetRequestWithQueryParamsForm(gateway.FormQueryParamsWithTenantIDAndUserIDFunc("tenantId", ""))),
+				queryOptions.requestResponseCallback).
 			Build(queryOptions.middlewares...)
 	}
 
@@ -143,9 +110,8 @@ func (params *EntityCRUDParams) crud(builder *gateway.Builder) {
 	if !getByIDOptions.disable {
 		builder.
 			Url(http.MethodGet, domainPath+"/get").
-			Get(&gateway.GetRequest{
-				Url: params.ServiceVersionedUrl + domainPath + "/get",
-			}, getByIDOptions.requestResponseCallback).
+			Get(gateway.NewGetRequest(params.ServiceVersionedUrl+domainPath+"/get"),
+				getByIDOptions.requestResponseCallback).
 			Build(getByIDOptions.middlewares...)
 	}
 }

+ 4 - 12
convenient/gwtools/many2many.go

@@ -44,9 +44,7 @@ func (params *Many2ManyParams) many2many(builder *gateway.Builder) {
 			// 左到右更新
 			builder.
 				Url(http.MethodPost, leftDomainPath+rightDomainPath+"/update").
-				Post(&gateway.PostRequest{
-					Url: params.ServiceVersionedUrl + leftDomainPath + rightDomainPath + "/update",
-				}, nil).
+				Post(gateway.NewPostRequest(params.ServiceVersionedUrl+leftDomainPath+rightDomainPath+"/update"), nil).
 				Build()
 		}
 
@@ -54,9 +52,7 @@ func (params *Many2ManyParams) many2many(builder *gateway.Builder) {
 			// 左到右查询
 			builder.
 				Url(http.MethodGet, leftDomainPath+rightDomainPath+"/query").
-				Get(&gateway.GetRequest{
-					Url: params.ServiceVersionedUrl + leftDomainPath + rightDomainPath + "/query",
-				}, nil).
+				Get(gateway.NewGetRequest(params.ServiceVersionedUrl+leftDomainPath+rightDomainPath+"/query"), nil).
 				Build()
 		}
 	}
@@ -66,9 +62,7 @@ func (params *Many2ManyParams) many2many(builder *gateway.Builder) {
 			// 右到左更新
 			builder.
 				Url(http.MethodPost, rightDomainPath+leftDomainPath+"/update").
-				Post(&gateway.PostRequest{
-					Url: params.ServiceVersionedUrl + rightDomainPath + leftDomainPath + "/update",
-				}, nil).
+				Post(gateway.NewPostRequest(params.ServiceVersionedUrl+rightDomainPath+leftDomainPath+"/update"), nil).
 				Build()
 		}
 
@@ -76,9 +70,7 @@ func (params *Many2ManyParams) many2many(builder *gateway.Builder) {
 			// 右到左查询
 			builder.
 				Url(http.MethodGet, rightDomainPath+leftDomainPath+"/query").
-				Get(&gateway.GetRequest{
-					Url: params.ServiceVersionedUrl + rightDomainPath + leftDomainPath + "/query",
-				}, nil).
+				Get(gateway.NewGetRequest(params.ServiceVersionedUrl+rightDomainPath+leftDomainPath+"/query"), nil).
 				Build()
 		}
 	}

+ 8 - 24
convenient/gwtools/one2many.go

@@ -1,7 +1,6 @@
 package gwtools
 
 import (
-	"git.sxidc.com/go-framework/baize/framework/core/api"
 	"git.sxidc.com/go-framework/baize/framework/gateway"
 	"git.sxidc.com/go-tools/utils/template"
 	"github.com/iancoleman/strcase"
@@ -45,9 +44,7 @@ func (params *One2ManyParams) one2many(builder *gateway.Builder) {
 			// 左到右更新
 			builder.
 				Url(http.MethodPost, leftDomainPath+rightDomainPath+"/update").
-				Post(&gateway.PostRequest{
-					Url: params.ServiceVersionedUrl + leftDomainPath + rightDomainPath + "/update",
-				}, nil).
+				Post(gateway.NewPostRequest(params.ServiceVersionedUrl+leftDomainPath+rightDomainPath+"/update"), nil).
 				Build()
 		}
 
@@ -55,9 +52,7 @@ func (params *One2ManyParams) one2many(builder *gateway.Builder) {
 			// 左到右查询
 			builder.
 				Url(http.MethodGet, leftDomainPath+rightDomainPath+"/query").
-				Get(&gateway.GetRequest{
-					Url: params.ServiceVersionedUrl + leftDomainPath + rightDomainPath + "/query",
-				}, nil).
+				Get(gateway.NewGetRequest(params.ServiceVersionedUrl+leftDomainPath+rightDomainPath+"/query"), nil).
 				Build()
 		}
 	}
@@ -67,9 +62,7 @@ func (params *One2ManyParams) one2many(builder *gateway.Builder) {
 			// 右到左更新
 			builder.
 				Url(http.MethodPost, rightDomainPath+leftDomainPath+"/update").
-				Post(&gateway.PostRequest{
-					Url: params.ServiceVersionedUrl + rightDomainPath + leftDomainPath + "/update",
-				}, nil).
+				Post(gateway.NewPostRequest(params.ServiceVersionedUrl+rightDomainPath+leftDomainPath+"/update"), nil).
 				Build()
 		}
 
@@ -77,9 +70,7 @@ func (params *One2ManyParams) one2many(builder *gateway.Builder) {
 			// 右到左查询
 			builder.
 				Url(http.MethodGet, rightDomainPath+leftDomainPath+"/query").
-				Get(&gateway.GetRequest{
-					Url: params.ServiceVersionedUrl + rightDomainPath + leftDomainPath + "/query",
-				}, nil).
+				Get(gateway.NewGetRequest(params.ServiceVersionedUrl+rightDomainPath+leftDomainPath+"/query"), nil).
 				Build()
 		}
 
@@ -87,17 +78,10 @@ func (params *One2ManyParams) one2many(builder *gateway.Builder) {
 			// 右到左查询,携带左方信息
 			builder.
 				Url(http.MethodGet, rightDomainPath+leftDomainPath+"/queryWith").
-				Request(func(c *api.Context, historyRequests []gateway.BuilderRequest, resultMap map[string]any) (gateway.BuilderRequest, error) {
-					err := gateway.AddQueryParamsTenantIDAndUserID(c, "tenantId", "")
-					if err != nil {
-						return nil, err
-					}
-
-					return &gateway.GetRequest{
-						Url:         params.ServiceVersionedUrl + rightDomainPath + leftDomainPath + "/queryWith",
-						QueryParams: c.GetQueryParams().Map(),
-					}, nil
-				}, nil).
+				Get(gateway.NewGetRequest(params.ServiceVersionedUrl+rightDomainPath+leftDomainPath+"/queryWith",
+					gateway.GetRequestWithQueryParamsForm(
+						gateway.FormQueryParamsWithTenantIDAndUserIDFunc("tenantId", ""))),
+					nil).
 				Build()
 		}
 	}

+ 12 - 35
convenient/gwtools/one2one.go

@@ -1,7 +1,6 @@
 package gwtools
 
 import (
-	"git.sxidc.com/go-framework/baize/framework/core/api"
 	"git.sxidc.com/go-framework/baize/framework/gateway"
 	"git.sxidc.com/go-tools/utils/template"
 	"github.com/iancoleman/strcase"
@@ -45,9 +44,7 @@ func (params *One2OneParams) one2one(builder *gateway.Builder) {
 			// 左到右更新
 			builder.
 				Url(http.MethodPost, leftDomainPath+rightDomainPath+"/update").
-				Post(&gateway.PostRequest{
-					Url: params.ServiceVersionedUrl + leftDomainPath + rightDomainPath + "/update",
-				}, nil).
+				Post(gateway.NewPostRequest(params.ServiceVersionedUrl+leftDomainPath+rightDomainPath+"/update"), nil).
 				Build()
 		}
 
@@ -55,9 +52,7 @@ func (params *One2OneParams) one2one(builder *gateway.Builder) {
 			// 左到右查询
 			builder.
 				Url(http.MethodGet, leftDomainPath+rightDomainPath+"/query").
-				Get(&gateway.GetRequest{
-					Url: params.ServiceVersionedUrl + leftDomainPath + rightDomainPath + "/query",
-				}, nil).
+				Get(gateway.NewGetRequest(params.ServiceVersionedUrl+leftDomainPath+rightDomainPath+"/query"), nil).
 				Build()
 		}
 
@@ -65,17 +60,10 @@ func (params *One2OneParams) one2one(builder *gateway.Builder) {
 			// 左到右查询,携带右方信息
 			builder.
 				Url(http.MethodGet, leftDomainPath+rightDomainPath+"/queryWith").
-				Request(func(c *api.Context, historyRequests []gateway.BuilderRequest, resultMap map[string]any) (gateway.BuilderRequest, error) {
-					err := gateway.AddQueryParamsTenantIDAndUserID(c, "tenantId", "")
-					if err != nil {
-						return nil, err
-					}
-
-					return &gateway.GetRequest{
-						Url:         params.ServiceVersionedUrl + leftDomainPath + rightDomainPath + "/queryWith",
-						QueryParams: c.GetQueryParams().Map(),
-					}, nil
-				}, nil).
+				Get(gateway.NewGetRequest(params.ServiceVersionedUrl+leftDomainPath+rightDomainPath+"/queryWith",
+					gateway.GetRequestWithQueryParamsForm(
+						gateway.FormQueryParamsWithTenantIDAndUserIDFunc("tenantId", ""))),
+					nil).
 				Build()
 		}
 	}
@@ -85,9 +73,7 @@ func (params *One2OneParams) one2one(builder *gateway.Builder) {
 			// 右到左更新
 			builder.
 				Url(http.MethodPost, rightDomainPath+leftDomainPath+"/update").
-				Post(&gateway.PostRequest{
-					Url: params.ServiceVersionedUrl + rightDomainPath + leftDomainPath + "/update",
-				}, nil).
+				Post(gateway.NewPostRequest(params.ServiceVersionedUrl+rightDomainPath+leftDomainPath+"/update"), nil).
 				Build()
 		}
 
@@ -95,9 +81,7 @@ func (params *One2OneParams) one2one(builder *gateway.Builder) {
 			// 右到左查询
 			builder.
 				Url(http.MethodGet, rightDomainPath+leftDomainPath+"/query").
-				Get(&gateway.GetRequest{
-					Url: params.ServiceVersionedUrl + rightDomainPath + leftDomainPath + "/query",
-				}, nil).
+				Get(gateway.NewGetRequest(params.ServiceVersionedUrl+rightDomainPath+leftDomainPath+"/query"), nil).
 				Build()
 		}
 
@@ -105,17 +89,10 @@ func (params *One2OneParams) one2one(builder *gateway.Builder) {
 			// 右到左查询,携带左方信息
 			builder.
 				Url(http.MethodGet, rightDomainPath+leftDomainPath+"/queryWith").
-				Request(func(c *api.Context, historyRequests []gateway.BuilderRequest, resultMap map[string]any) (gateway.BuilderRequest, error) {
-					err := gateway.AddQueryParamsTenantIDAndUserID(c, "tenantId", "")
-					if err != nil {
-						return nil, err
-					}
-
-					return &gateway.GetRequest{
-						Url:         params.ServiceVersionedUrl + rightDomainPath + leftDomainPath + "/queryWith",
-						QueryParams: c.GetQueryParams().Map(),
-					}, nil
-				}, nil).
+				Get(gateway.NewGetRequest(params.ServiceVersionedUrl+rightDomainPath+leftDomainPath+"/queryWith",
+					gateway.GetRequestWithQueryParamsForm(
+						gateway.FormQueryParamsWithTenantIDAndUserIDFunc("tenantId", ""))),
+					nil).
 				Build()
 		}
 	}

+ 10 - 30
convenient/gwtools/value_object_crud.go

@@ -57,22 +57,10 @@ func (params *ValueObjectCRUDParams) crud(builder *gateway.Builder) {
 	if !createOptions.disable {
 		builder.
 			Url(http.MethodPost, domainPath+"/create").
-			Request(func(c *api.Context, historyRequests []gateway.BuilderRequest, resultMap map[string]any) (gateway.BuilderRequest, error) {
-				err := gateway.AddJsonBodyTenantIDAndUserID(c, "tenantId", "createUserId")
-				if err != nil {
-					return nil, err
-				}
-
-				jsonBody, err := c.GetJsonBody()
-				if err != nil {
-					return nil, err
-				}
-
-				return &gateway.PostRequest{
-					Url:  params.ServiceVersionedUrl + domainPath + "/create",
-					Body: jsonBody.Map(),
-				}, nil
-			}, createOptions.requestResponseCallback).
+			Post(gateway.NewPostRequest(params.ServiceVersionedUrl+domainPath+"/create",
+				gateway.PostRequestWithBodyForm(
+					gateway.FormJsonBodyWithTenantIDAndUserIDFunc("tenantId", "createUserId"))),
+				createOptions.requestResponseCallback).
 			Build(createOptions.middlewares...)
 	}
 
@@ -80,9 +68,8 @@ func (params *ValueObjectCRUDParams) crud(builder *gateway.Builder) {
 	if !deleteOptions.disable {
 		builder.
 			Url(http.MethodPost, domainPath+"/delete").
-			Post(&gateway.PostRequest{
-				Url: params.ServiceVersionedUrl + domainPath + "/delete",
-			}, deleteOptions.requestResponseCallback).
+			Post(gateway.NewPostRequest(params.ServiceVersionedUrl+domainPath+"/delete"),
+				deleteOptions.requestResponseCallback).
 			Build(deleteOptions.middlewares...)
 	}
 
@@ -90,17 +77,10 @@ func (params *ValueObjectCRUDParams) crud(builder *gateway.Builder) {
 	if !queryOptions.disable {
 		builder.
 			Url(http.MethodGet, domainPath+"/query").
-			Request(func(c *api.Context, historyRequests []gateway.BuilderRequest, resultMap map[string]any) (gateway.BuilderRequest, error) {
-				err := gateway.AddQueryParamsTenantIDAndUserID(c, "tenantId", "")
-				if err != nil {
-					return nil, err
-				}
-
-				return &gateway.GetRequest{
-					Url:         params.ServiceVersionedUrl + domainPath + "/query",
-					QueryParams: c.GetQueryParams().Map(),
-				}, nil
-			}, queryOptions.requestResponseCallback).
+			Get(gateway.NewGetRequest(params.ServiceVersionedUrl+domainPath+"/query",
+				gateway.GetRequestWithQueryParamsForm(
+					gateway.FormQueryParamsWithTenantIDAndUserIDFunc("tenantId", ""))),
+				queryOptions.requestResponseCallback).
 			Build(queryOptions.middlewares...)
 	}
 }

+ 10 - 78
framework/gateway/builder.go

@@ -7,8 +7,6 @@ import (
 	"time"
 )
 
-type FormBuilderRequestFunc func(c *api.Context, historyRequests []BuilderRequest, resultMap map[string]any) (BuilderRequest, error)
-
 type GlobalRequestResponseCallback func(c *api.Context, request BuilderRequest, historyRequests []BuilderRequest, resultMap map[string]any) error
 type RequestResponseCallback func(c *api.Context, response *http_client.Response, historyRequests []BuilderRequest, resultMap map[string]any) error
 
@@ -40,83 +38,23 @@ func (builder *Builder) Url(httpMethod string, relativePath string) *Builder {
 }
 
 func (builder *Builder) Post(request *PostRequest, requestCallbackFunc RequestResponseCallback) *Builder {
-	return builder.Request(func(c *api.Context, historyRequests []BuilderRequest, resultMap map[string]any) (BuilderRequest, error) {
-		if request.Body == nil {
-			body, err := c.GetBytesBody()
-			if err != nil {
-				return nil, err
-			}
-
-			request.Body = body
-		}
-
-		return &PostRequest{
-			Url:     request.Url,
-			Headers: request.Headers,
-			Body:    request.Body,
-		}, nil
-	}, requestCallbackFunc)
+	return builder.request(request, requestCallbackFunc)
 }
 
 func (builder *Builder) Delete(request *DeleteRequest, requestCallbackFunc RequestResponseCallback) *Builder {
-	return builder.Request(func(c *api.Context, historyRequests []BuilderRequest, resultMap map[string]any) (BuilderRequest, error) {
-		if request.PathParams == nil {
-			request.PathParams = c.GetPathParams().Map()
-		}
-
-		if request.QueryParams == nil {
-			request.QueryParams = c.GetQueryParams().Map()
-		}
-
-		return &DeleteRequest{
-			Url:         request.Url,
-			Headers:     request.Headers,
-			PathParams:  request.PathParams,
-			QueryParams: request.QueryParams,
-		}, nil
-	}, requestCallbackFunc)
+	return builder.request(request, requestCallbackFunc)
 }
 
 func (builder *Builder) Put(request *PutRequest, requestCallbackFunc RequestResponseCallback) *Builder {
-	return builder.Request(func(c *api.Context, historyRequests []BuilderRequest, resultMap map[string]any) (BuilderRequest, error) {
-		if request.Body == nil {
-			body, err := c.GetBytesBody()
-			if err != nil {
-				return nil, err
-			}
-
-			request.Body = body
-		}
-
-		return &PutRequest{
-			Url:     request.Url,
-			Headers: request.Headers,
-			Body:    request.Body,
-		}, nil
-	}, requestCallbackFunc)
+	return builder.request(request, requestCallbackFunc)
 }
 
 func (builder *Builder) Get(request *GetRequest, requestCallbackFunc RequestResponseCallback) *Builder {
-	return builder.Request(func(c *api.Context, historyRequests []BuilderRequest, resultMap map[string]any) (BuilderRequest, error) {
-		if request.PathParams == nil {
-			request.PathParams = c.GetPathParams().Map()
-		}
-
-		if request.QueryParams == nil {
-			request.QueryParams = c.GetQueryParams().Map()
-		}
-
-		return &GetRequest{
-			Url:         request.Url,
-			Headers:     request.Headers,
-			PathParams:  request.PathParams,
-			QueryParams: request.QueryParams,
-		}, nil
-	}, requestCallbackFunc)
+	return builder.request(request, requestCallbackFunc)
 }
 
-func (builder *Builder) Request(formBuilderRequestFunc FormBuilderRequestFunc, requestCallbackFunc RequestResponseCallback) *Builder {
-	return builder.addRequest(newBuilderRequestItem(formBuilderRequestFunc, requestCallbackFunc))
+func (builder *Builder) request(builderRequest BuilderRequest, requestCallbackFunc RequestResponseCallback) *Builder {
+	return builder.addRequest(newBuilderRequestItem(builderRequest, requestCallbackFunc))
 }
 
 func (builder *Builder) GlobalRequestCallback(globalRequestResponseCallback GlobalRequestResponseCallback) *Builder {
@@ -146,20 +84,14 @@ func (builder *Builder) Build(middlewares ...api.Handler) {
 			resultMap := make(map[string]any)
 
 			for _, requestItem := range builder.params.requestItems {
-				request, err := requestItem.formBuilderRequestFuc(c, historyRequests, resultMap)
-				if err != nil {
-					builder.params.responseErrorCallback(c, errors.New(err.Error()))
-					return
-				}
-
-				err = request.Request(httpRequest)
+				requestWithResponse, err := requestItem.builderRequest.Request(c, httpRequest, historyRequests, resultMap)
 				if err != nil {
 					builder.params.responseErrorCallback(c, errors.New(err.Error()))
 					return
 				}
 
 				if requestItem.requestResponseCallback != nil {
-					err := requestItem.requestResponseCallback(c, request.Response(), historyRequests, resultMap)
+					err := requestItem.requestResponseCallback(c, requestWithResponse.Response(), historyRequests, resultMap)
 					if err != nil {
 						builder.params.responseErrorCallback(c, errors.New(err.Error()))
 						return
@@ -169,7 +101,7 @@ func (builder *Builder) Build(middlewares ...api.Handler) {
 				}
 
 				if builder.params.globalRequestResponseCallback != nil {
-					err := builder.params.globalRequestResponseCallback(c, request, historyRequests, resultMap)
+					err := builder.params.globalRequestResponseCallback(c, requestWithResponse, historyRequests, resultMap)
 					if err != nil {
 						builder.params.responseErrorCallback(c, errors.New(err.Error()))
 						return
@@ -178,7 +110,7 @@ func (builder *Builder) Build(middlewares ...api.Handler) {
 					continue
 				}
 
-				historyRequests = append(historyRequests, request)
+				historyRequests = append(historyRequests, requestWithResponse)
 			}
 
 			builder.params.responseSuccessCallback(c, historyRequests, resultMap)

+ 411 - 67
framework/gateway/builder_request.go

@@ -1,143 +1,487 @@
 package gateway
 
 import (
+	"git.sxidc.com/go-framework/baize/framework/core/api"
 	"git.sxidc.com/go-tools/utils/http_client"
-	"net/http"
 )
 
+type UrlTransferFunc func(c *api.Context, url string, historyRequest []BuilderRequest, resultMap map[string]any) (string, error)
+type HeadersFormFunc func(c *api.Context, historyRequest []BuilderRequest, resultMap map[string]any) (map[string]string, error)
+type BodyFormFunc func(c *api.Context, historyRequest []BuilderRequest, resultMap map[string]any) (any, error)
+type QueryParamsFormFunc func(c *api.Context, historyRequest []BuilderRequest, resultMap map[string]any) (map[string]string, error)
+type PathParamsFormFunc func(c *api.Context, historyRequest []BuilderRequest, resultMap map[string]any) (map[string]string, error)
+
+func FormJsonBodyWithTenantIDAndUserIDFunc(tenantIDFieldName string, userIDFieldName string) BodyFormFunc {
+	return func(c *api.Context, historyRequest []BuilderRequest, resultMap map[string]any) (any, error) {
+		err := AddJsonBodyTenantIDAndUserID(c, tenantIDFieldName, userIDFieldName)
+		if err != nil {
+			return nil, err
+		}
+
+		jsonBody, err := c.GetJsonBody()
+		if err != nil {
+			return nil, err
+		}
+
+		return jsonBody, nil
+	}
+}
+
+func FormQueryParamsWithTenantIDAndUserIDFunc(tenantIDFieldName string, userIDFieldName string) QueryParamsFormFunc {
+	return func(c *api.Context, historyRequest []BuilderRequest, resultMap map[string]any) (map[string]string, error) {
+		err := AddQueryParamsTenantIDAndUserID(c, tenantIDFieldName, userIDFieldName)
+		if err != nil {
+			return nil, err
+		}
+
+		return c.GetQueryParams().Map(), nil
+	}
+}
+
 type BuilderRequest interface {
-	HttpMethod() string
-	Request(request *http_client.Request) error
+	Request(c *api.Context, request *http_client.Request, historyRequest []BuilderRequest, resultMap map[string]any) (BuilderRequest, error)
 	Response() *http_client.Response
 }
 
-type PostRequest struct {
-	Url     string
-	Headers map[string]string
-	Body    any
+type PostRequestOption func(options *PostRequestOptions)
 
-	response *http_client.Response
+type PostRequestOptions struct {
+	urlTransferFunc UrlTransferFunc
+	headersFormFunc HeadersFormFunc
+	bodyFormFunc    BodyFormFunc
+}
+
+func PostRequestWithUrlTransferFunc(urlTransferFunc UrlTransferFunc) PostRequestOption {
+	return func(options *PostRequestOptions) {
+		options.urlTransferFunc = urlTransferFunc
+	}
+}
+
+func PostRequestWithHeadersForm(headersFormFunc HeadersFormFunc) PostRequestOption {
+	return func(options *PostRequestOptions) {
+		options.headersFormFunc = headersFormFunc
+	}
 }
 
-func (req *PostRequest) HttpMethod() string {
-	return http.MethodPost
+func PostRequestWithBodyForm(bodyFormFunc BodyFormFunc) PostRequestOption {
+	return func(options *PostRequestOptions) {
+		options.bodyFormFunc = bodyFormFunc
+	}
+}
+
+type PostRequest struct {
+	url      string
+	response *http_client.Response
+	options  *PostRequestOptions
 }
 
-func (req *PostRequest) RequestUrl() string {
-	return req.Url
+func NewPostRequest(url string, opts ...PostRequestOption) *PostRequest {
+	options := new(PostRequestOptions)
+
+	for _, opt := range opts {
+		opt(options)
+	}
+
+	if options.urlTransferFunc == nil {
+		options.urlTransferFunc = defaultUrlTransferFunc
+	}
+
+	if options.headersFormFunc == nil {
+		options.headersFormFunc = defaultHeadersFormFunc
+	}
+
+	if options.bodyFormFunc == nil {
+		options.bodyFormFunc = defaultBodyFormFunc
+	}
+
+	return &PostRequest{
+		url:     url,
+		options: options,
+	}
 }
 
-func (req *PostRequest) Request(request *http_client.Request) error {
-	response, err := request.Post(req.Url, req.Body,
-		http_client.WithRequestHeaders(req.Headers))
+func (req *PostRequest) Request(c *api.Context, request *http_client.Request, historyRequest []BuilderRequest, resultMap map[string]any) (BuilderRequest, error) {
+	url, err := req.options.urlTransferFunc(c, req.url, historyRequest, resultMap)
 	if err != nil {
-		return err
+		return nil, err
 	}
 
-	req.response = response
+	headers, err := req.options.headersFormFunc(c, historyRequest, resultMap)
+	if err != nil {
+		return nil, err
+	}
+
+	body, err := req.options.bodyFormFunc(c, historyRequest, resultMap)
+	if err != nil {
+		return nil, err
+	}
 
-	return nil
+	response, err := request.Post(url, body, http_client.WithRequestHeaders(headers))
+	if err != nil {
+		return nil, err
+	}
+
+	return &PostRequest{
+		url:      url,
+		response: response,
+		options: &PostRequestOptions{
+			urlTransferFunc: req.options.urlTransferFunc,
+			headersFormFunc: req.options.headersFormFunc,
+			bodyFormFunc:    req.options.bodyFormFunc,
+		},
+	}, nil
 }
 
 func (req *PostRequest) Response() *http_client.Response {
 	return req.response
 }
 
-type DeleteRequest struct {
-	Url         string
-	Headers     map[string]string
-	PathParams  map[string]string
-	QueryParams map[string]string
+type DeleteRequestOption func(options *DeleteRequestOptions)
+
+type DeleteRequestOptions struct {
+	urlTransferFunc     UrlTransferFunc
+	headersFormFunc     HeadersFormFunc
+	pathParamsFormFunc  PathParamsFormFunc
+	queryParamsFormFunc QueryParamsFormFunc
+}
+
+func DeleteRequestWithUrlTransferFunc(urlTransferFunc UrlTransferFunc) DeleteRequestOption {
+	return func(options *DeleteRequestOptions) {
+		options.urlTransferFunc = urlTransferFunc
+	}
+}
+
+func DeleteRequestWithHeadersForm(headersFormFunc HeadersFormFunc) DeleteRequestOption {
+	return func(options *DeleteRequestOptions) {
+		options.headersFormFunc = headersFormFunc
+	}
+}
+
+func DeleteRequestWithPathParamsForm(pathParamsFormFunc PathParamsFormFunc) DeleteRequestOption {
+	return func(options *DeleteRequestOptions) {
+		options.pathParamsFormFunc = pathParamsFormFunc
+	}
+}
 
+func DeleteRequestWithQueryParamsForm(queryParamsFormFunc QueryParamsFormFunc) DeleteRequestOption {
+	return func(options *DeleteRequestOptions) {
+		options.queryParamsFormFunc = queryParamsFormFunc
+	}
+}
+
+type DeleteRequest struct {
+	url      string
 	response *http_client.Response
+	options  *DeleteRequestOptions
 }
 
-func (req *DeleteRequest) HttpMethod() string {
-	return http.MethodDelete
+func NewDeleteRequest(url string, opts ...DeleteRequestOption) *DeleteRequest {
+	options := new(DeleteRequestOptions)
+
+	for _, opt := range opts {
+		opt(options)
+	}
+
+	if options.urlTransferFunc == nil {
+		options.urlTransferFunc = defaultUrlTransferFunc
+	}
+
+	if options.headersFormFunc == nil {
+		options.headersFormFunc = defaultHeadersFormFunc
+	}
+
+	if options.pathParamsFormFunc == nil {
+		options.pathParamsFormFunc = defaultPathParamsFormFunc
+	}
+
+	if options.queryParamsFormFunc == nil {
+		options.queryParamsFormFunc = defaultQueryParamsFormFunc
+	}
+
+	return &DeleteRequest{
+		url:     url,
+		options: options,
+	}
 }
 
-func (req *DeleteRequest) Request(request *http_client.Request) error {
-	response, err := request.Delete(req.Url,
-		http_client.WithRequestHeaders(req.Headers),
-		http_client.WithRequestPathParams(req.PathParams),
-		http_client.WithRequestQueryParams(req.QueryParams))
+func (req *DeleteRequest) Request(c *api.Context, request *http_client.Request, historyRequest []BuilderRequest, resultMap map[string]any) (BuilderRequest, error) {
+	url, err := req.options.urlTransferFunc(c, req.url, historyRequest, resultMap)
+	if err != nil {
+		return nil, err
+	}
+
+	headers, err := req.options.headersFormFunc(c, historyRequest, resultMap)
+	if err != nil {
+		return nil, err
+	}
+
+	pathParams, err := req.options.pathParamsFormFunc(c, historyRequest, resultMap)
+	if err != nil {
+		return nil, err
+	}
+
+	queryParams, err := req.options.queryParamsFormFunc(c, historyRequest, resultMap)
 	if err != nil {
-		return err
+		return nil, err
 	}
 
-	req.response = response
+	response, err := request.Delete(url,
+		http_client.WithRequestHeaders(headers),
+		http_client.WithRequestPathParams(pathParams),
+		http_client.WithRequestQueryParams(queryParams))
+	if err != nil {
+		return nil, err
+	}
 
-	return nil
+	return &DeleteRequest{
+		url:      url,
+		response: response,
+		options: &DeleteRequestOptions{
+			urlTransferFunc:     req.options.urlTransferFunc,
+			headersFormFunc:     req.options.headersFormFunc,
+			pathParamsFormFunc:  req.options.pathParamsFormFunc,
+			queryParamsFormFunc: req.options.queryParamsFormFunc,
+		},
+	}, nil
 }
 
 func (req *DeleteRequest) Response() *http_client.Response {
 	return req.response
 }
 
-type PutRequest struct {
-	// 静态配置
-	Url     string
-	Headers map[string]string
-	Body    any
+type PutRequestOption func(options *PutRequestOptions)
 
-	response *http_client.Response
+type PutRequestOptions struct {
+	urlTransferFunc UrlTransferFunc
+	headersFormFunc HeadersFormFunc
+	bodyFormFunc    BodyFormFunc
 }
 
-func (req *PutRequest) HttpMethod() string {
-	return http.MethodPut
+func PutRequestWithUrlTransferFunc(urlTransferFunc UrlTransferFunc) PutRequestOption {
+	return func(options *PutRequestOptions) {
+		options.urlTransferFunc = urlTransferFunc
+	}
 }
 
-func (req *PutRequest) RequestUrl() string {
-	return req.Url
+func PutRequestWithHeadersForm(headersFormFunc HeadersFormFunc) PutRequestOption {
+	return func(options *PutRequestOptions) {
+		options.headersFormFunc = headersFormFunc
+	}
+}
+
+func PutRequestWithBodyForm(bodyFormFunc BodyFormFunc) PutRequestOption {
+	return func(options *PutRequestOptions) {
+		options.bodyFormFunc = bodyFormFunc
+	}
+}
+
+type PutRequest struct {
+	url      string
+	response *http_client.Response
+	options  *PutRequestOptions
+}
+
+func NewPutRequest(url string, opts ...PutRequestOption) *PutRequest {
+	options := new(PutRequestOptions)
+
+	for _, opt := range opts {
+		opt(options)
+	}
+
+	if options.urlTransferFunc == nil {
+		options.urlTransferFunc = defaultUrlTransferFunc
+	}
+
+	if options.headersFormFunc == nil {
+		options.headersFormFunc = defaultHeadersFormFunc
+	}
+
+	if options.bodyFormFunc == nil {
+		options.bodyFormFunc = defaultBodyFormFunc
+	}
+
+	return &PutRequest{
+		url:     url,
+		options: options,
+	}
 }
 
-func (req *PutRequest) Request(request *http_client.Request) error {
-	response, err := request.Put(req.Url, req.Body,
-		http_client.WithRequestHeaders(req.Headers))
+func (req *PutRequest) Request(c *api.Context, request *http_client.Request, historyRequest []BuilderRequest, resultMap map[string]any) (BuilderRequest, error) {
+	url, err := req.options.urlTransferFunc(c, req.url, historyRequest, resultMap)
 	if err != nil {
-		return err
+		return nil, err
 	}
 
-	req.response = response
+	headers, err := req.options.headersFormFunc(c, historyRequest, resultMap)
+	if err != nil {
+		return nil, err
+	}
+
+	body, err := req.options.bodyFormFunc(c, historyRequest, resultMap)
+	if err != nil {
+		return nil, err
+	}
 
-	return nil
+	response, err := request.Put(url, body, http_client.WithRequestHeaders(headers))
+	if err != nil {
+		return nil, err
+	}
+
+	return &PutRequest{
+		url:      url,
+		response: response,
+		options: &PutRequestOptions{
+			urlTransferFunc: req.options.urlTransferFunc,
+			headersFormFunc: req.options.headersFormFunc,
+			bodyFormFunc:    req.options.bodyFormFunc,
+		},
+	}, nil
 }
 
 func (req *PutRequest) Response() *http_client.Response {
 	return req.response
 }
 
-type GetRequest struct {
-	Url         string
-	Headers     map[string]string
-	PathParams  map[string]string
-	QueryParams map[string]string
+type GetRequestOption func(options *GetRequestOptions)
 
-	response *http_client.Response
+type GetRequestOptions struct {
+	urlTransferFunc     UrlTransferFunc
+	headersFormFunc     HeadersFormFunc
+	pathParamsFormFunc  PathParamsFormFunc
+	queryParamsFormFunc QueryParamsFormFunc
 }
 
-func (req *GetRequest) HttpMethod() string {
-	return http.MethodGet
+func GetRequestWithUrlTransferFunc(urlTransferFunc UrlTransferFunc) GetRequestOption {
+	return func(options *GetRequestOptions) {
+		options.urlTransferFunc = urlTransferFunc
+	}
+}
+
+func GetRequestWithHeadersForm(headersFormFunc HeadersFormFunc) GetRequestOption {
+	return func(options *GetRequestOptions) {
+		options.headersFormFunc = headersFormFunc
+	}
+}
+
+func GetRequestWithPathParamsForm(pathParamsFormFunc PathParamsFormFunc) GetRequestOption {
+	return func(options *GetRequestOptions) {
+		options.pathParamsFormFunc = pathParamsFormFunc
+	}
 }
 
-func (req *GetRequest) RequestUrl() string {
-	return req.Url
+func GetRequestWithQueryParamsForm(queryParamsFormFunc QueryParamsFormFunc) GetRequestOption {
+	return func(options *GetRequestOptions) {
+		options.queryParamsFormFunc = queryParamsFormFunc
+	}
 }
 
-func (req *GetRequest) Request(request *http_client.Request) error {
-	response, err := request.Get(req.Url,
-		http_client.WithRequestHeaders(req.Headers),
-		http_client.WithRequestPathParams(req.PathParams),
-		http_client.WithRequestQueryParams(req.QueryParams))
+type GetRequest struct {
+	url         string
+	headers     map[string]string
+	pathParams  map[string]string
+	queryParams map[string]string
+	response    *http_client.Response
+	options     *GetRequestOptions
+}
+
+func NewGetRequest(url string, opts ...GetRequestOption) *GetRequest {
+	options := new(GetRequestOptions)
+
+	for _, opt := range opts {
+		opt(options)
+	}
+
+	if options.urlTransferFunc == nil {
+		options.urlTransferFunc = defaultUrlTransferFunc
+	}
+
+	if options.headersFormFunc == nil {
+		options.headersFormFunc = defaultHeadersFormFunc
+	}
+
+	if options.pathParamsFormFunc == nil {
+		options.pathParamsFormFunc = defaultPathParamsFormFunc
+	}
+
+	if options.queryParamsFormFunc == nil {
+		options.queryParamsFormFunc = defaultQueryParamsFormFunc
+	}
+
+	return &GetRequest{
+		url:     url,
+		options: options,
+	}
+}
+
+func (req *GetRequest) Request(c *api.Context, request *http_client.Request, historyRequest []BuilderRequest, resultMap map[string]any) (BuilderRequest, error) {
+	url, err := req.options.urlTransferFunc(c, req.url, historyRequest, resultMap)
 	if err != nil {
-		return err
+		return nil, err
 	}
 
-	req.response = response
+	headers, err := req.options.headersFormFunc(c, historyRequest, resultMap)
+	if err != nil {
+		return nil, err
+	}
+
+	pathParams, err := req.options.pathParamsFormFunc(c, historyRequest, resultMap)
+	if err != nil {
+		return nil, err
+	}
 
-	return nil
+	queryParams, err := req.options.queryParamsFormFunc(c, historyRequest, resultMap)
+	if err != nil {
+		return nil, err
+	}
+
+	response, err := request.Get(url,
+		http_client.WithRequestHeaders(headers),
+		http_client.WithRequestPathParams(pathParams),
+		http_client.WithRequestQueryParams(queryParams))
+	if err != nil {
+		return nil, err
+	}
+
+	return &GetRequest{
+		url:         url,
+		headers:     headers,
+		pathParams:  pathParams,
+		queryParams: queryParams,
+		response:    response,
+		options: &GetRequestOptions{
+			urlTransferFunc:     req.options.urlTransferFunc,
+			headersFormFunc:     req.options.headersFormFunc,
+			pathParamsFormFunc:  req.options.pathParamsFormFunc,
+			queryParamsFormFunc: req.options.queryParamsFormFunc,
+		},
+	}, nil
 }
 
 func (req *GetRequest) Response() *http_client.Response {
 	return req.response
 }
+
+func defaultUrlTransferFunc(_ *api.Context, url string, _ []BuilderRequest, _ map[string]any) (string, error) {
+	return url, nil
+}
+
+func defaultHeadersFormFunc(c *api.Context, _ []BuilderRequest, _ map[string]any) (map[string]string, error) {
+	return c.GetHeaders(), nil
+}
+
+func defaultBodyFormFunc(c *api.Context, _ []BuilderRequest, _ map[string]any) (any, error) {
+	cachedBody, err := c.GetBytesBody()
+	if err != nil {
+		return nil, err
+	}
+
+	return cachedBody.Bytes(), nil
+}
+
+func defaultQueryParamsFormFunc(c *api.Context, _ []BuilderRequest, _ map[string]any) (map[string]string, error) {
+	return c.GetQueryParams().Map(), nil
+}
+
+func defaultPathParamsFormFunc(c *api.Context, _ []BuilderRequest, _ map[string]any) (map[string]string, error) {
+	return c.GetPathParams().Map(), nil
+}

+ 3 - 3
framework/gateway/builder_request_item.go

@@ -1,13 +1,13 @@
 package gateway
 
 type builderRequestItem struct {
-	formBuilderRequestFuc   FormBuilderRequestFunc
+	builderRequest          BuilderRequest
 	requestResponseCallback RequestResponseCallback
 }
 
-func newBuilderRequestItem(formBuilderRequestFuc FormBuilderRequestFunc, requestResponseCallback RequestResponseCallback) *builderRequestItem {
+func newBuilderRequestItem(builderRequest BuilderRequest, requestResponseCallback RequestResponseCallback) *builderRequestItem {
 	return &builderRequestItem{
-		formBuilderRequestFuc:   formBuilderRequestFuc,
+		builderRequest:          builderRequest,
 		requestResponseCallback: requestResponseCallback,
 	}
 }

+ 21 - 17
framework/gateway/common.go

@@ -11,25 +11,29 @@ func AddJsonBodyTenantIDAndUserID(c *api.Context, tenantIDField string, userIDFi
 		return err
 	}
 
-	tenantID := jsonBody.Get(tenantIDField)
-	if tenantID == nil {
-		tenantInfo := c.GetTenantInfo()
-
-		if tenantInfo != nil {
-			jsonBody.Set(tenantIDField, tenantInfo.GetID())
-		} else {
-			jsonBody.Set(tenantIDField, "guest-"+strutils.SimpleUUID()[:26])
+	if strutils.IsStringNotEmpty(tenantIDField) {
+		tenantID := jsonBody.Get(tenantIDField)
+		if tenantID == nil {
+			tenantInfo := c.GetTenantInfo()
+
+			if tenantInfo != nil {
+				jsonBody.Set(tenantIDField, tenantInfo.GetID())
+			} else {
+				jsonBody.Set(tenantIDField, "guest-"+strutils.SimpleUUID()[:26])
+			}
 		}
 	}
 
-	userID := jsonBody.Get(userIDField)
-	if userID == nil {
-		userInfo := c.GetUserInfo()
+	if strutils.IsStringNotEmpty(userIDField) {
+		userID := jsonBody.Get(userIDField)
+		if userID == nil {
+			userInfo := c.GetUserInfo()
 
-		if userInfo != nil {
-			jsonBody.Set(userIDField, userInfo.GetID())
-		} else {
-			jsonBody.Set(userIDField, "guest-"+strutils.SimpleUUID()[:26])
+			if userInfo != nil {
+				jsonBody.Set(userIDField, userInfo.GetID())
+			} else {
+				jsonBody.Set(userIDField, "guest-"+strutils.SimpleUUID()[:26])
+			}
 		}
 	}
 
@@ -39,14 +43,14 @@ func AddJsonBodyTenantIDAndUserID(c *api.Context, tenantIDField string, userIDFi
 func AddQueryParamsTenantIDAndUserID(c *api.Context, tenantIDField string, userIDField string) error {
 	queryParams := c.GetQueryParams()
 
-	if c.GetTenantInfo() != nil {
+	if c.GetTenantInfo() != nil && strutils.IsStringNotEmpty(tenantIDField) {
 		tenantID := queryParams.Get(tenantIDField)
 		if strutils.IsStringEmpty(tenantID) {
 			queryParams.Set(tenantIDField, c.GetTenantInfo().GetID())
 		}
 	}
 
-	if c.GetUserInfo() != nil {
+	if c.GetUserInfo() != nil && strutils.IsStringNotEmpty(userIDField) {
 		userID := queryParams.Get(userIDField)
 		if strutils.IsStringEmpty(userID) {
 			queryParams.Set(userIDField, c.GetUserInfo().GetID())