@@ -20,25 +20,31 @@ type Option func(*Options)
20
20
21
21
// Options options
22
22
type Options struct {
23
- actions []response.Action
24
- search response.Searcher
25
- model actions.Model
26
- auth bool
27
- noAuthAction []string
28
- depth int
29
- treeField string
30
- modelProvider actions.ModelProvider
31
- scope func (ctx * gin.Context , table schema.Tabler ) func (db * gorm.DB ) * gorm.DB
32
- beforeCreate func (ctx * gin.Context , db * gorm.DB , m schema.Tabler ) error
33
- beforeUpdate func (ctx * gin.Context , db * gorm.DB , m schema.Tabler ) error
34
- afterCreate func (ctx * gin.Context , db * gorm.DB , m schema.Tabler ) error
35
- afterUpdate func (ctx * gin.Context , db * gorm.DB , m schema.Tabler ) error
36
- beforeGet func (ctx * gin.Context , db * gorm.DB , m schema.Tabler ) error
37
- afterGet func (ctx * gin.Context , db * gorm.DB , m schema.Tabler ) error
38
- beforeDelete func (ctx * gin.Context , db * gorm.DB , m schema.Tabler ) error
39
- afterDelete func (ctx * gin.Context , db * gorm.DB , m schema.Tabler ) error
40
- beforeSearch func (ctx * gin.Context , db * gorm.DB , m schema.Tabler ) error
41
- afterSearch func (ctx * gin.Context , db * gorm.DB , m schema.Tabler ) error
23
+ actions []response.Action
24
+ search response.Searcher
25
+ model actions.Model
26
+ auth bool
27
+ noAuthAction []string
28
+ depth int
29
+ treeField string
30
+ modelProvider actions.ModelProvider
31
+ scope func (ctx * gin.Context , table schema.Tabler ) func (db * gorm.DB ) * gorm.DB
32
+ beforeCreate func (ctx * gin.Context , db * gorm.DB , m schema.Tabler ) error
33
+ beforeUpdate func (ctx * gin.Context , db * gorm.DB , m schema.Tabler ) error
34
+ afterCreate func (ctx * gin.Context , db * gorm.DB , m schema.Tabler ) error
35
+ afterUpdate func (ctx * gin.Context , db * gorm.DB , m schema.Tabler ) error
36
+ beforeGet func (ctx * gin.Context , db * gorm.DB , m schema.Tabler ) error
37
+ afterGet func (ctx * gin.Context , db * gorm.DB , m schema.Tabler ) error
38
+ beforeDelete func (ctx * gin.Context , db * gorm.DB , m schema.Tabler ) error
39
+ afterDelete func (ctx * gin.Context , db * gorm.DB , m schema.Tabler ) error
40
+ beforeSearch func (ctx * gin.Context , db * gorm.DB , m schema.Tabler ) error
41
+ afterSearch func (ctx * gin.Context , db * gorm.DB , m schema.Tabler ) error
42
+ handlers gin.HandlersChain
43
+ createHandlers gin.HandlersChain
44
+ updateHandlers gin.HandlersChain
45
+ getHandlers gin.HandlersChain
46
+ deleteHandlers gin.HandlersChain
47
+ searchHandlers gin.HandlersChain
42
48
}
43
49
44
50
func (o * Options ) needAuth (name string ) bool {
@@ -136,6 +142,98 @@ func WithTreeField(treeField string) Option {
136
142
}
137
143
}
138
144
139
- func WithBeforeControl () {
145
+ func WithBeforeCreate (beforeCreate func (ctx * gin.Context , db * gorm.DB , m schema.Tabler ) error ) Option {
146
+ return func (o * Options ) {
147
+ o .beforeCreate = beforeCreate
148
+ }
149
+ }
150
+
151
+ func WithAfterCreate (afterCreate func (ctx * gin.Context , db * gorm.DB , m schema.Tabler ) error ) Option {
152
+ return func (o * Options ) {
153
+ o .afterCreate = afterCreate
154
+ }
155
+ }
156
+
157
+ func WithBeforeUpdate (beforeUpdate func (ctx * gin.Context , db * gorm.DB , m schema.Tabler ) error ) Option {
158
+ return func (o * Options ) {
159
+ o .beforeUpdate = beforeUpdate
160
+ }
161
+ }
162
+
163
+ func WithAfterUpdate (afterUpdate func (ctx * gin.Context , db * gorm.DB , m schema.Tabler ) error ) Option {
164
+ return func (o * Options ) {
165
+ o .afterUpdate = afterUpdate
166
+ }
167
+ }
168
+
169
+ func WithBeforeGet (beforeGet func (ctx * gin.Context , db * gorm.DB , m schema.Tabler ) error ) Option {
170
+ return func (o * Options ) {
171
+ o .beforeGet = beforeGet
172
+ }
173
+ }
174
+
175
+ func WithAfterGet (afterGet func (ctx * gin.Context , db * gorm.DB , m schema.Tabler ) error ) Option {
176
+ return func (o * Options ) {
177
+ o .afterGet = afterGet
178
+ }
179
+ }
180
+
181
+ func WithBeforeDelete (beforeDelete func (ctx * gin.Context , db * gorm.DB , m schema.Tabler ) error ) Option {
182
+ return func (o * Options ) {
183
+ o .beforeDelete = beforeDelete
184
+ }
185
+ }
186
+
187
+ func WithAfterDelete (afterDelete func (ctx * gin.Context , db * gorm.DB , m schema.Tabler ) error ) Option {
188
+ return func (o * Options ) {
189
+ o .afterDelete = afterDelete
190
+ }
191
+ }
140
192
193
+ func WithBeforeSearch (beforeSearch func (ctx * gin.Context , db * gorm.DB , m schema.Tabler ) error ) Option {
194
+ return func (o * Options ) {
195
+ o .beforeSearch = beforeSearch
196
+ }
197
+ }
198
+
199
+ func WithAfterSearch (afterSearch func (ctx * gin.Context , db * gorm.DB , m schema.Tabler ) error ) Option {
200
+ return func (o * Options ) {
201
+ o .afterSearch = afterSearch
202
+ }
203
+ }
204
+
205
+ func WithHandlers (handlers gin.HandlersChain ) Option {
206
+ return func (o * Options ) {
207
+ o .handlers = handlers
208
+ }
209
+ }
210
+
211
+ func WithCreateHandlers (handlers gin.HandlersChain ) Option {
212
+ return func (o * Options ) {
213
+ o .createHandlers = handlers
214
+ }
215
+ }
216
+
217
+ func WithUpdateHandlers (handlers gin.HandlersChain ) Option {
218
+ return func (o * Options ) {
219
+ o .updateHandlers = handlers
220
+ }
221
+ }
222
+
223
+ func WithGetHandlers (handlers gin.HandlersChain ) Option {
224
+ return func (o * Options ) {
225
+ o .getHandlers = handlers
226
+ }
227
+ }
228
+
229
+ func WithDeleteHandlers (handlers gin.HandlersChain ) Option {
230
+ return func (o * Options ) {
231
+ o .deleteHandlers = handlers
232
+ }
233
+ }
234
+
235
+ func WithSearchHandlers (handlers gin.HandlersChain ) Option {
236
+ return func (o * Options ) {
237
+ o .searchHandlers = handlers
238
+ }
141
239
}
0 commit comments