|
|
@@ -9,23 +9,23 @@ import (
|
|
|
)
|
|
|
|
|
|
func CRUD(builder *gateway.Builder, params *CRUDParams, opts ...any) {
|
|
|
- createOptions := new(CreateOptions)
|
|
|
- deleteOptions := new(DeleteOptions)
|
|
|
- updateOptions := new(UpdateOptions)
|
|
|
- queryOptions := new(QueryOptions)
|
|
|
- getByIDOptions := new(GetByIDOptions)
|
|
|
+ createOptions := new(CRUDCreateOptions)
|
|
|
+ deleteOptions := new(CRUDDeleteOptions)
|
|
|
+ updateOptions := new(CRUDUpdateOptions)
|
|
|
+ queryOptions := new(CRUDQueryOptions)
|
|
|
+ getByIDOptions := new(CRUDGetByIDOptions)
|
|
|
|
|
|
for _, opt := range opts {
|
|
|
switch o := opt.(type) {
|
|
|
- case CreateOption:
|
|
|
+ case CRUDCreateOption:
|
|
|
o(createOptions)
|
|
|
- case DeleteOption:
|
|
|
+ case CRUDDeleteOption:
|
|
|
o(deleteOptions)
|
|
|
- case UpdateOption:
|
|
|
+ case CRUDUpdateOption:
|
|
|
o(updateOptions)
|
|
|
- case QueryOption:
|
|
|
+ case CRUDQueryOption:
|
|
|
o(queryOptions)
|
|
|
- case GetByIDOption:
|
|
|
+ case CRUDGetByIDOption:
|
|
|
o(getByIDOptions)
|
|
|
default:
|
|
|
continue
|
|
|
@@ -49,11 +49,11 @@ type CRUDParams struct {
|
|
|
DomainCamelName string
|
|
|
|
|
|
// 可选配置项,通过WithXXX配置
|
|
|
- createOptions *CreateOptions
|
|
|
- deleteOptions *DeleteOptions
|
|
|
- updateOptions *UpdateOptions
|
|
|
- queryOptions *QueryOptions
|
|
|
- getByIDOptions *GetByIDOptions
|
|
|
+ createOptions *CRUDCreateOptions
|
|
|
+ deleteOptions *CRUDDeleteOptions
|
|
|
+ updateOptions *CRUDUpdateOptions
|
|
|
+ queryOptions *CRUDQueryOptions
|
|
|
+ getByIDOptions *CRUDGetByIDOptions
|
|
|
}
|
|
|
|
|
|
func (params *CRUDParams) crud(builder *gateway.Builder) {
|
|
|
@@ -122,13 +122,13 @@ func (params *CRUDParams) crud(builder *gateway.Builder) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-type CreateOption func(options *CreateOptions)
|
|
|
-type DeleteOption func(options *DeleteOptions)
|
|
|
-type UpdateOption func(options *UpdateOptions)
|
|
|
-type QueryOption func(options *QueryOptions)
|
|
|
-type GetByIDOption func(options *GetByIDOptions)
|
|
|
+type CRUDCreateOption func(options *CRUDCreateOptions)
|
|
|
+type CRUDDeleteOption func(options *CRUDDeleteOptions)
|
|
|
+type CRUDUpdateOption func(options *CRUDUpdateOptions)
|
|
|
+type CRUDQueryOption func(options *CRUDQueryOptions)
|
|
|
+type CRUDGetByIDOption func(options *CRUDGetByIDOptions)
|
|
|
|
|
|
-type CreateOptions struct {
|
|
|
+type CRUDCreateOptions struct {
|
|
|
// 关闭创建
|
|
|
disable bool
|
|
|
|
|
|
@@ -145,7 +145,7 @@ type CreateOptions struct {
|
|
|
getUserIDFunc GetUserIDFunc
|
|
|
}
|
|
|
|
|
|
-type DeleteOptions struct {
|
|
|
+type CRUDDeleteOptions struct {
|
|
|
// 关闭删除
|
|
|
disable bool
|
|
|
|
|
|
@@ -156,7 +156,7 @@ type DeleteOptions struct {
|
|
|
middlewares []api.Handler
|
|
|
}
|
|
|
|
|
|
-type UpdateOptions struct {
|
|
|
+type CRUDUpdateOptions struct {
|
|
|
// 关闭更新
|
|
|
disable bool
|
|
|
|
|
|
@@ -170,7 +170,7 @@ type UpdateOptions struct {
|
|
|
getUserIDFunc GetUserIDFunc
|
|
|
}
|
|
|
|
|
|
-type QueryOptions struct {
|
|
|
+type CRUDQueryOptions struct {
|
|
|
// 关闭查询
|
|
|
disable bool
|
|
|
|
|
|
@@ -184,7 +184,7 @@ type QueryOptions struct {
|
|
|
getTenantIDFunc GetTenantIDFunc
|
|
|
}
|
|
|
|
|
|
-type GetByIDOptions struct {
|
|
|
+type CRUDGetByIDOptions struct {
|
|
|
// 关闭根据ID查询
|
|
|
disable bool
|
|
|
|
|
|
@@ -195,110 +195,110 @@ type GetByIDOptions struct {
|
|
|
middlewares []api.Handler
|
|
|
}
|
|
|
|
|
|
-func WithCreateCallbacks(callbacks gateway.RequestCallbackFunc) CreateOption {
|
|
|
- return func(options *CreateOptions) {
|
|
|
+func WithCRUDCreateCallbacks(callbacks gateway.RequestCallbackFunc) CRUDCreateOption {
|
|
|
+ return func(options *CRUDCreateOptions) {
|
|
|
options.callback = callbacks
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithCreateMiddlewares(middlewares []api.Handler) CreateOption {
|
|
|
- return func(options *CreateOptions) {
|
|
|
+func WithCRUDCreateMiddlewares(middlewares []api.Handler) CRUDCreateOption {
|
|
|
+ return func(options *CRUDCreateOptions) {
|
|
|
options.middlewares = middlewares
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithCreateGetTenantIDFunc(getTenantIDFunc GetTenantIDFunc) CreateOption {
|
|
|
- return func(options *CreateOptions) {
|
|
|
+func WithCRUDCreateGetTenantIDFunc(getTenantIDFunc GetTenantIDFunc) CRUDCreateOption {
|
|
|
+ return func(options *CRUDCreateOptions) {
|
|
|
options.getTenantIDFunc = getTenantIDFunc
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithCreateGetUserIDFunc(getUserIDFunc GetUserIDFunc) CreateOption {
|
|
|
- return func(options *CreateOptions) {
|
|
|
+func WithCRUDCreateGetUserIDFunc(getUserIDFunc GetUserIDFunc) CRUDCreateOption {
|
|
|
+ return func(options *CRUDCreateOptions) {
|
|
|
options.getUserIDFunc = getUserIDFunc
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithDisableDelete() DeleteOption {
|
|
|
- return func(options *DeleteOptions) {
|
|
|
+func WithCRUDDisableDelete() CRUDDeleteOption {
|
|
|
+ return func(options *CRUDDeleteOptions) {
|
|
|
options.disable = true
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithDeleteCallbacks(callbacks gateway.RequestCallbackFunc) DeleteOption {
|
|
|
- return func(options *DeleteOptions) {
|
|
|
+func WithCRUDDeleteCallbacks(callbacks gateway.RequestCallbackFunc) CRUDDeleteOption {
|
|
|
+ return func(options *CRUDDeleteOptions) {
|
|
|
options.callback = callbacks
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithDeleteMiddlewares(middlewares []api.Handler) DeleteOption {
|
|
|
- return func(options *DeleteOptions) {
|
|
|
+func WithCRUDDeleteMiddlewares(middlewares []api.Handler) CRUDDeleteOption {
|
|
|
+ return func(options *CRUDDeleteOptions) {
|
|
|
options.middlewares = middlewares
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithDisableUpdate() UpdateOption {
|
|
|
- return func(options *UpdateOptions) {
|
|
|
+func WithCRUDDisableUpdate() CRUDUpdateOption {
|
|
|
+ return func(options *CRUDUpdateOptions) {
|
|
|
options.disable = true
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithUpdateCallbacks(callbacks gateway.RequestCallbackFunc) UpdateOption {
|
|
|
- return func(options *UpdateOptions) {
|
|
|
+func WithCRUDUpdateCallbacks(callbacks gateway.RequestCallbackFunc) CRUDUpdateOption {
|
|
|
+ return func(options *CRUDUpdateOptions) {
|
|
|
options.callback = callbacks
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithUpdateMiddlewares(middlewares []api.Handler) UpdateOption {
|
|
|
- return func(options *UpdateOptions) {
|
|
|
+func WithCRUDUpdateMiddlewares(middlewares []api.Handler) CRUDUpdateOption {
|
|
|
+ return func(options *CRUDUpdateOptions) {
|
|
|
options.middlewares = middlewares
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithUpdateGetUserIDFunc(getUserIDFunc GetUserIDFunc) UpdateOption {
|
|
|
- return func(options *UpdateOptions) {
|
|
|
+func WithCRUDUpdateGetUserIDFunc(getUserIDFunc GetUserIDFunc) CRUDUpdateOption {
|
|
|
+ return func(options *CRUDUpdateOptions) {
|
|
|
options.getUserIDFunc = getUserIDFunc
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithDisableQuery() QueryOption {
|
|
|
- return func(options *QueryOptions) {
|
|
|
+func WithCRUDDisableQuery() CRUDQueryOption {
|
|
|
+ return func(options *CRUDQueryOptions) {
|
|
|
options.disable = true
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithQueryCallbacks(callbacks gateway.RequestCallbackFunc) QueryOption {
|
|
|
- return func(options *QueryOptions) {
|
|
|
+func WithCRUDQueryCallbacks(callbacks gateway.RequestCallbackFunc) CRUDQueryOption {
|
|
|
+ return func(options *CRUDQueryOptions) {
|
|
|
options.callback = callbacks
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithQueryMiddlewares(middlewares []api.Handler) QueryOption {
|
|
|
- return func(options *QueryOptions) {
|
|
|
+func WithCRUDQueryMiddlewares(middlewares []api.Handler) CRUDQueryOption {
|
|
|
+ return func(options *CRUDQueryOptions) {
|
|
|
options.middlewares = middlewares
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithQueryGetTenantIDFunc(getTenantIDFunc GetTenantIDFunc) QueryOption {
|
|
|
- return func(options *QueryOptions) {
|
|
|
+func WithCRUDQueryGetTenantIDFunc(getTenantIDFunc GetTenantIDFunc) CRUDQueryOption {
|
|
|
+ return func(options *CRUDQueryOptions) {
|
|
|
options.getTenantIDFunc = getTenantIDFunc
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithDisableGetByID() GetByIDOption {
|
|
|
- return func(options *GetByIDOptions) {
|
|
|
+func WithCRUDDisableGetByID() CRUDGetByIDOption {
|
|
|
+ return func(options *CRUDGetByIDOptions) {
|
|
|
options.disable = true
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithGetByIDCallbacks(callbacks gateway.RequestCallbackFunc) GetByIDOption {
|
|
|
- return func(options *GetByIDOptions) {
|
|
|
+func WithCRUDGetByIDCallbacks(callbacks gateway.RequestCallbackFunc) CRUDGetByIDOption {
|
|
|
+ return func(options *CRUDGetByIDOptions) {
|
|
|
options.callback = callbacks
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-func WithGetByIDMiddlewares(middlewares []api.Handler) GetByIDOption {
|
|
|
- return func(options *GetByIDOptions) {
|
|
|
+func WithCRUDGetByIDMiddlewares(middlewares []api.Handler) CRUDGetByIDOption {
|
|
|
+ return func(options *CRUDGetByIDOptions) {
|
|
|
options.middlewares = middlewares
|
|
|
}
|
|
|
}
|