|
|
@@ -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
|
|
|
+}
|