package pass_through import ( "git.sxidc.com/go-framework/baize/framework/gateway" "git.sxidc.com/go-tools/utils/http_client" "git.sxidc.com/go-tools/utils/strutils" "net/http" ) // PostRoute POST直传API // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func PostRoute(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodPost, opts...) } // DeleteRoute DELETE直传API // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func DeleteRoute(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodDelete, opts...) } // PutRoute PUT直传API // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func PutRoute(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodPut, opts...) } // GetRoute GET直传API // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func GetRoute(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodGet, opts...) } // PostRouteWithTenantIDAndUserID POST直传API,请求Body是JsonBody,且会添加租户ID和用户ID字段,字段名分别为tenantId和userId // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func PostRouteWithTenantIDAndUserID(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodPost, append(opts, WithTenantIDParamsName("tenantId"), WithUserIDParamsName("userId"))...) } // PostRouteWithTenantIDAndCreateUserID POST直传API,请求Body是JsonBody,且会添加租户ID和用户ID字段,字段名分别为tenantId和createUserId // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func PostRouteWithTenantIDAndCreateUserID(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodPost, append(opts, WithTenantIDParamsName("tenantId"), WithUserIDParamsName("createUserId"))...) } // DeleteRouteWithTenantIDAndUserID DELETE直传API,会在查询参数添加租户ID和用户ID字段,字段名分别为tenantId和userId // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func DeleteRouteWithTenantIDAndUserID(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodDelete, append(opts, WithTenantIDParamsName("tenantId"), WithUserIDParamsName("userId"))...) } // DeleteRouteWithTenantIDAndDeleteUserID DELETE直传API,会在查询参数添加租户ID和用户ID字段,字段名分别为tenantId和deleteUserId // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func DeleteRouteWithTenantIDAndDeleteUserID(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodDelete, append(opts, WithTenantIDParamsName("tenantId"), WithUserIDParamsName("deleteUserId"))...) } // PutRouteWithTenantIDAndUserID PUT直传API,请求Body是JsonBody,且会添加租户ID和用户ID字段,字段名分别为tenantId和userId // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func PutRouteWithTenantIDAndUserID(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodPut, append(opts, WithTenantIDParamsName("tenantId"), WithUserIDParamsName("userId"))...) } // PutRouteWithTenantIDAndUpdateUserID PUT直传API,请求Body是JsonBody,且会添加租户ID和用户ID字段,字段名分别为tenantId和updateUserId // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func PutRouteWithTenantIDAndUpdateUserID(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodPut, append(opts, WithTenantIDParamsName("tenantId"), WithUserIDParamsName("updateUserId"))...) } // PostRouteWithTenantIDAndUserInfo POST直传API,请求Body是JsonBody,且会添加租户ID,用户ID以及操作者用户名字段,字段名分别为tenantId,userId和operatorUserName // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func PostRouteWithTenantIDAndUserInfo(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodPost, append(opts, WithTenantIDParamsName("tenantId"), WithUserIDParamsName("userId"), WithUserNameParamsName("operatorUserName"))...) } // PostRouteWithTenantIDAndCreateUserInfo POST直传API,请求Body是JsonBody,且会添加租户ID和用户ID字段,字段名分别为为tenantId,userId和operatorUserName // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func PostRouteWithTenantIDAndCreateUserInfo(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodPost, append(opts, WithTenantIDParamsName("tenantId"), WithUserIDParamsName("createUserId"), WithUserNameParamsName("operatorUserName"))...) } // DeleteRouteWithTenantIDAndUserInfo DELETE直传API,会在查询参数添加租户ID和用户ID字段,字段名分别为为tenantId,userId和operatorUserName // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func DeleteRouteWithTenantIDAndUserInfo(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodDelete, append(opts, WithTenantIDParamsName("tenantId"), WithUserIDParamsName("userId"), WithUserNameParamsName("operatorUserName"))...) } // DeleteRouteWithTenantIDAndDeleteUserInfo DELETE直传API,会在查询参数添加租户ID和用户ID字段,字段名分别为为tenantId,userId和operatorUserName // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func DeleteRouteWithTenantIDAndDeleteUserInfo(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodDelete, append(opts, WithTenantIDParamsName("tenantId"), WithUserIDParamsName("deleteUserId"), WithUserNameParamsName("operatorUserName"))...) } // PutRouteWithTenantIDAndUserInfo PUT直传API,请求Body是JsonBody,且会添加租户ID和用户ID字段,字段名分别为为tenantId,userId和operatorUserName // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func PutRouteWithTenantIDAndUserInfo(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodPut, append(opts, WithTenantIDParamsName("tenantId"), WithUserIDParamsName("userId"), WithUserNameParamsName("operatorUserName"))...) } // PutRouteWithTenantIDAndUpdateUserInfo PUT直传API,请求Body是JsonBody,且会添加租户ID和用户ID字段,字段名分别为为tenantId,userId和operatorUserName // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func PutRouteWithTenantIDAndUpdateUserInfo(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodPut, append(opts, WithTenantIDParamsName("tenantId"), WithUserIDParamsName("updateUserId"), WithUserNameParamsName("operatorUserName"))...) } // GetRouteWithTenantIDAndUserID GET直传API,会在查询参数添加租户ID和用户ID字段,字段名分别为tenantId和userId // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func GetRouteWithTenantIDAndUserID(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodGet, append(opts, WithTenantIDParamsName("tenantId"), WithUserIDParamsName("userId"))...) } // GetRouteWithTenantIDAndCreateUserID GET直传API,会在查询参数添加租户ID和用户ID字段,字段名分别为tenantId和createUserId // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func GetRouteWithTenantIDAndCreateUserID(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodGet, append(opts, WithTenantIDParamsName("tenantId"), WithUserIDParamsName("createUserId"))...) } // GetRouteWithTenantIDAndDeleteUserID GET直传API,会在查询参数添加租户ID和用户ID字段,字段名分别为tenantId和deleteUserId // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func GetRouteWithTenantIDAndDeleteUserID(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodGet, append(opts, WithTenantIDParamsName("tenantId"), WithUserIDParamsName("deleteUserId"))...) } // GetRouteWithTenantIDAndUpdateUserID GET直传API,会在查询参数添加租户ID和用户ID字段,字段名分别为tenantId和updateUserId // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func GetRouteWithTenantIDAndUpdateUserID(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodGet, append(opts, WithTenantIDParamsName("tenantId"), WithUserIDParamsName("updateUserId"))...) } // PostRouteWithTenantID POST直传API,请求Body是JsonBody,且会添加租户ID字段,字段名分别为tenantId // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func PostRouteWithTenantID(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodPost, append(opts, WithTenantIDParamsName("tenantId"))...) } // DeleteRouteWithTenantID DELETE直传API,会在查询参数添加租户ID字段,字段名分别为tenantId // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func DeleteRouteWithTenantID(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodDelete, append(opts, WithTenantIDParamsName("tenantId"))...) } // PutRouteWithTenantID PUT直传API,请求Body是JsonBody,且会添加租户ID字段,字段名分别为tenantId // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func PutRouteWithTenantID(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodPut, append(opts, WithTenantIDParamsName("tenantId"))...) } // GetRouteWithTenantID GET直传API,会在查询参数添加租户ID字段,字段名分别为tenantId // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func GetRouteWithTenantID(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodGet, append(opts, WithTenantIDParamsName("tenantId"))...) } // PostRouteWithUserID POST直传API,请求Body是JsonBody,且会添加用户ID字段,字段名分别为userId // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func PostRouteWithUserID(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodPost, append(opts, WithUserIDParamsName("userId"))...) } // PostRouteWithCreateUserID POST直传API,请求Body是JsonBody,且会添加用户ID字段,字段名分别为createUserId // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func PostRouteWithCreateUserID(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodPost, append(opts, WithUserIDParamsName("createUserId"))...) } // DeleteRouteWithUserID DELETE直传API,会在查询参数添加用户ID字段,字段名分别为userId // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func DeleteRouteWithUserID(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodDelete, append(opts, WithUserIDParamsName("userId"))...) } // DeleteRouteWithDeleteUserID DELETE直传API,会在查询参数添加用户ID字段,字段名分别为deleteUserId // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func DeleteRouteWithDeleteUserID(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodDelete, append(opts, WithUserIDParamsName("deleteUserId"))...) } // PutRouteWithUserID PUT直传API,请求Body是JsonBody,且会添加用户ID字段,字段名分别为createUserId // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func PutRouteWithUserID(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodPut, append(opts, WithUserIDParamsName("userId"))...) } // PutRouteWithUpdateUserID PUT直传API,请求Body是JsonBody,且会添加用户ID字段,字段名分别为updateUserId // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func PutRouteWithUpdateUserID(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodPut, append(opts, WithUserIDParamsName("updateUserId"))...) } // PostRouteWithUserInfo POST直传API,请求Body是JsonBody,且会添加用户ID字段,字段名分别为userId,还会添加操作者用户名,字段名为operatorUserName // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func PostRouteWithUserInfo(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodPost, append(opts, WithUserIDParamsName("userId"), WithUserNameParamsName("operatorUserName"))...) } // PostRouteWithCreateUserInfo POST直传API,请求Body是JsonBody,且会添加用户ID字段,字段名分别为createUserId,还会添加操作者用户名,字段名为operatorUserName // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func PostRouteWithCreateUserInfo(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodPost, append(opts, WithUserIDParamsName("createUserId"), WithUserNameParamsName("operatorUserName"))...) } // DeleteRouteWithUserInfo DELETE直传API,会在查询参数添加用户ID字段,字段名分别为userId,还会添加操作者用户名,字段名为operatorUserName // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func DeleteRouteWithUserInfo(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodDelete, append(opts, WithUserIDParamsName("userId"), WithUserNameParamsName("operatorUserName"))...) } // DeleteRouteWithDeleteUserInfo DELETE直传API,会在查询参数添加用户ID字段,字段名分别为deleteUserId,还会添加操作者用户名,字段名为operatorUserName // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func DeleteRouteWithDeleteUserInfo(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodDelete, append(opts, WithUserIDParamsName("deleteUserId"), WithUserNameParamsName("operatorUserName"))...) } // PutRouteWithUserInfo PUT直传API,请求Body是JsonBody,且会添加用户ID字段,字段名分别为createUserId,还会添加操作者用户名,字段名为operatorUserName // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func PutRouteWithUserInfo(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodPut, append(opts, WithUserIDParamsName("userId"), WithUserNameParamsName("operatorUserName"))...) } // PutRouteWithUpdateUserInfo PUT直传API,请求Body是JsonBody,且会添加用户ID字段,字段名分别为updateUserId,还会添加操作者用户名,字段名为operatorUserName // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func PutRouteWithUpdateUserInfo(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodPut, append(opts, WithUserIDParamsName("updateUserId"), WithUserNameParamsName("operatorUserName"))...) } // GetRouteWithUserID GET直传API,会在查询参数添加用户ID字段,字段名分别为userId // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func GetRouteWithUserID(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodGet, append(opts, WithUserIDParamsName("userId"))...) } // GetRouteWithCreateUserID GET直传API,会在查询参数添加用户ID字段,字段名分别为createUserId // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func GetRouteWithCreateUserID(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodGet, append(opts, WithUserIDParamsName("createUserId"))...) } // GetRouteWithDeleteUserID GET直传API,会在查询参数添加用户ID字段,字段名分别为deleteUserId // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func GetRouteWithDeleteUserID(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodGet, append(opts, WithUserIDParamsName("deleteUserId"))...) } // GetRouteWithUpdateUserID GET直传API,会在查询参数添加用户ID字段,字段名分别为updateUserId // 参数: // - builder: 该网关API构建器 // - params: 网关直通参数 // - opts: 网关直通选项 // 返回值: 无 func GetRouteWithUpdateUserID(builder *gateway.Builder, params *Simple, opts ...Option) { params.passThrough(builder, http.MethodGet, append(opts, WithUserIDParamsName("updateUserId"))...) } // Simple 参数 type Simple struct { // RelativePath 网关开放API的RelativePath RelativePath string // 服务的URL ServiceUrl string } func (params *Simple) passThrough(builder *gateway.Builder, httpMethod string, opts ...Option) { options := new(Options) for _, opt := range opts { opt(options) } builder.AddRoute(httpMethod, params.RelativePath, func(requestBuilder *gateway.RequestBuilder) { if options.responseSuccessCallback != nil { requestBuilder.ResponseSuccessCallback(func(c *gateway.RequestBuilderContext) { err := options.responseSuccessCallback(c) if err != nil { requestBuilder.ResponseError(err) return } }) } if options.responseErrorCallback != nil { requestBuilder.ResponseErrorCallback(func(c *gateway.RequestBuilderContext, err error) { retErr := options.responseErrorCallback(c, err) if retErr != nil { requestBuilder.ResponseError(retErr) return } }) } if strutils.IsStringNotEmpty(options.tenantIDParamsName) || strutils.IsStringNotEmpty(options.userIDParamsName) { if httpMethod == http.MethodPost || httpMethod == http.MethodPut { err := gateway.AddJsonBodyTenantIDAndUserInfo(requestBuilder, options.tenantIDParamsName, options.userIDParamsName, options.userNameParamsName) if err != nil { requestBuilder.ResponseError(err) return } } if httpMethod == http.MethodDelete || httpMethod == http.MethodGet { err := gateway.AddQueryParamsTenantIDAndUserInfo(requestBuilder, options.tenantIDParamsName, options.userIDParamsName, options.userNameParamsName) if err != nil { requestBuilder.ResponseError(err) return } } } requestOptions := make([]gateway.RequestOption, 0) if options.beforeRequestCallback != nil { requestOptions = append(requestOptions, gateway.WithBeforeRequestCallback( func(c *gateway.RequestBuilderContext) error { err := options.beforeRequestCallback(c) if err != nil { return err } return nil })) } if options.afterRequestCallback != nil { requestOptions = append(requestOptions, gateway.WithRequestResponseCallback( func(c *gateway.RequestBuilderContext, response *http_client.Response) error { err := options.afterRequestCallback(c) if err != nil { return err } return nil })) } switch httpMethod { case http.MethodPost: requestBuilder.Post(&gateway.PostRequest{ Url: params.ServiceUrl, }, requestOptions...) case http.MethodDelete: requestBuilder.Delete(&gateway.DeleteRequest{ Url: params.ServiceUrl, }, requestOptions...) case http.MethodPut: requestBuilder.Put(&gateway.PutRequest{ Url: params.ServiceUrl, }, requestOptions...) case http.MethodGet: requestBuilder.Get(&gateway.GetRequest{ Url: params.ServiceUrl, }, requestOptions...) default: panic("不支持的请求类型") } requestBuilder.Request() }, options.middlewares...) } type RequestBuilderCallback func(c *gateway.RequestBuilderContext) error type RequestBuilderErrCallback func(c *gateway.RequestBuilderContext, err error) error type Option func(options *Options) type Options struct { // tenantIDParamsName 租户ID请求参数名称 tenantIDParamsName string // userIDParamsName 用户ID请求参数名称 userIDParamsName string // userNameParamsName 用户名请求参数名称 userNameParamsName string // beforeRequestCallback 请求前回调 beforeRequestCallback RequestBuilderCallback // afterRequestCallback 请求后回调 afterRequestCallback RequestBuilderCallback // responseSuccessCallback 成功响应回调 responseSuccessCallback RequestBuilderCallback // responseErrorCallback 失败响应回调 responseErrorCallback RequestBuilderErrCallback // 中间件 middlewares []gateway.Handler } // WithTenantIDParamsName 设置请求参数中的租户ID参数的名称 func WithTenantIDParamsName(tenantIDParamsName string) Option { return func(options *Options) { options.tenantIDParamsName = tenantIDParamsName } } // WithUserIDParamsName 设置请求参数中的用户ID参数的名称 func WithUserIDParamsName(userIDParamsName string) Option { return func(options *Options) { options.userIDParamsName = userIDParamsName } } // WithUserNameParamsName 设置请求参数中的用户名参数的名称 func WithUserNameParamsName(userNameParamsName string) Option { return func(options *Options) { options.userNameParamsName = userNameParamsName } } // WithBeforeRequestCallback 设置请求前回调 func WithBeforeRequestCallback(callback RequestBuilderCallback) Option { return func(options *Options) { options.beforeRequestCallback = callback } } // WithAfterRequestCallback 设置请求后回调 func WithAfterRequestCallback(callback RequestBuilderCallback) Option { return func(options *Options) { options.afterRequestCallback = callback } } // WithResponseSuccessCallback 设置成功响应回调,默认回调会将服务响应作为网关API的响应返回 func WithResponseSuccessCallback(callback RequestBuilderCallback) Option { return func(options *Options) { options.responseSuccessCallback = callback } } // WithResponseErrorCallback 设置失败响应回调,默认回调会按照是否存在错误返回MsgResponse func WithResponseErrorCallback(callback RequestBuilderErrCallback) Option { return func(options *Options) { options.responseErrorCallback = callback } } // WithMiddlewares 设置中间件 func WithMiddlewares(middlewares ...gateway.Handler) Option { return func(options *Options) { options.middlewares = middlewares } }