|
|
@@ -7,155 +7,327 @@ import (
|
|
|
"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"))...)
|
|
|
}
|
|
|
|
|
|
+// 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"))...)
|
|
|
}
|
|
|
|
|
|
+// 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
|
|
|
- ServiceUrl string
|
|
|
+
|
|
|
+ // 服务的URL
|
|
|
+ ServiceUrl string
|
|
|
}
|
|
|
|
|
|
func (params *Simple) passThrough(builder *gateway.Builder, httpMethod string, opts ...Option) {
|
|
|
@@ -266,42 +438,49 @@ type Options struct {
|
|
|
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
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// 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 gateway.ResponseSuccessCallback) Option {
|
|
|
return func(options *Options) {
|
|
|
options.responseSuccessCallback = callback
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// WithResponseErrorCallback 设置失败响应回调,默认回调会按照是否存在错误返回MsgResponse
|
|
|
func WithResponseErrorCallback(callback gateway.ResponseErrorCallback) Option {
|
|
|
return func(options *Options) {
|
|
|
options.responseErrorCallback = callback
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// WithMiddlewares 设置中间件
|
|
|
func WithMiddlewares(middlewares ...gateway.Handler) Option {
|
|
|
return func(options *Options) {
|
|
|
options.middlewares = middlewares
|