-
Notifications
You must be signed in to change notification settings - Fork 189
/
resource.go
765 lines (658 loc) · 21 KB
/
resource.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
package admin
import (
"errors"
"fmt"
"net/http"
"path"
"reflect"
"strings"
"github.com/jinzhu/gorm"
"github.com/jinzhu/inflection"
"github.com/qor/qor"
"github.com/qor/qor/resource"
"github.com/qor/qor/utils"
"github.com/qor/roles"
)
// Config resource config struct
type Config struct {
Name string
IconName string
Menu []string
Permission *roles.Permission
Themes []ThemeInterface
Priority int
Singleton bool
Invisible bool
PageCount int
}
// Resource is the most important thing for qor admin, every model is defined as a resource, qor admin will genetate management interface based on its definition
type Resource struct {
*resource.Resource
Config *Config
ParentResource *Resource
SearchHandler func(keyword string, context *qor.Context) *gorm.DB
params string
admin *Admin
metas []*Meta
actions []*Action
scopes []*Scope
filters []*Filter
mounted bool
sections struct {
IndexSections []*Section
OverriddingIndexAttrs bool
OverriddingIndexAttrsCallbacks []func()
NewSections []*Section
OverriddingNewAttrs bool
OverriddingNewAttrsCallbacks []func()
EditSections []*Section
OverriddingEditAttrs bool
OverriddingEditAttrsCallbacks []func()
ShowSections []*Section
OverriddingShowAttrs bool
ConfiguredShowAttrs bool
OverriddingShowAttrsCallbacks []func()
SortableAttrs *[]string
}
}
// GetAdmin get admin from resource
func (res Resource) GetAdmin() *Admin {
return res.admin
}
// ToParam used as urls to register routes for resource
func (res *Resource) ToParam() string {
if res.params == "" {
if value, ok := res.Value.(interface {
ToParam() string
}); ok {
res.params = value.ToParam()
} else {
if res.Config.Singleton == true {
res.params = utils.ToParamString(res.Name)
} else {
res.params = utils.ToParamString(inflection.Plural(res.Name))
}
}
}
return res.params
}
// ParamIDName return param name for primary key like :product_id
func (res Resource) ParamIDName() string {
return fmt.Sprintf(":%v_id", inflection.Singular(utils.ToParamString(res.Name)))
}
// RoutePrefix return route prefix of resource
func (res *Resource) RoutePrefix() string {
var params string
for res.ParentResource != nil {
params = path.Join(res.ParentResource.ToParam(), res.ParentResource.ParamIDName(), params)
res = res.ParentResource
}
return params
}
// GetPrimaryValue get priamry value from request
func (res Resource) GetPrimaryValue(request *http.Request) string {
if request != nil {
return request.URL.Query().Get(res.ParamIDName())
}
return ""
}
// UseTheme use them for resource, will auto load the theme's javascripts, stylesheets for this resource
func (res *Resource) UseTheme(theme interface{}) []ThemeInterface {
var themeInterface ThemeInterface
if ti, ok := theme.(ThemeInterface); ok {
themeInterface = ti
} else if str, ok := theme.(string); ok {
for _, theme := range res.Config.Themes {
if theme.GetName() == str {
return res.Config.Themes
}
}
themeInterface = Theme{Name: str}
}
if themeInterface != nil {
res.Config.Themes = append(res.Config.Themes, themeInterface)
// Config Admin Theme
for _, pth := range themeInterface.GetViewPaths() {
res.GetAdmin().RegisterViewPath(pth)
}
themeInterface.ConfigAdminTheme(res)
}
return res.Config.Themes
}
// GetTheme get registered theme with name
func (res *Resource) GetTheme(name string) ThemeInterface {
for _, theme := range res.Config.Themes {
if theme.GetName() == name {
return theme
}
}
return nil
}
// NewResource initialize a new qor resource, won't add it to admin, just initialize it
func (res *Resource) NewResource(value interface{}, config ...*Config) *Resource {
subRes := res.GetAdmin().newResource(value, config...)
subRes.ParentResource = res
subRes.configure()
return subRes
}
// AddSubResource register sub-resource
func (res *Resource) AddSubResource(fieldName string, config ...*Config) (subRes *Resource, err error) {
var (
admin = res.GetAdmin()
scope = &gorm.Scope{Value: res.Value}
)
if field, ok := scope.FieldByName(fieldName); ok && field.Relationship != nil {
modelType := utils.ModelType(reflect.New(field.Struct.Type).Interface())
subRes = admin.NewResource(reflect.New(modelType).Interface(), config...)
subRes.setupParentResource(field.StructField.Name, res)
subRes.Action(&Action{
Name: "Delete",
Method: "DELETE",
URL: func(record interface{}, context *Context) string {
return context.URLFor(record, subRes)
},
Permission: subRes.Config.Permission,
Modes: []string{"menu_item"},
})
admin.RegisterResourceRouters(subRes, "create", "update", "read", "delete")
return
}
err = errors.New("invalid sub resource")
return
}
func (res *Resource) setupParentResource(fieldName string, parent *Resource) {
res.ParentResource = parent
var findParent = func(context *qor.Context) (interface{}, error) {
clone := context.Clone()
clone.ResourceID = parent.GetPrimaryValue(context.Request)
parentValue := parent.NewStruct()
err := parent.FindOneHandler(parentValue, nil, clone)
return parentValue, err
}
findOneHandler := res.FindOneHandler
res.FindOneHandler = func(value interface{}, metaValues *resource.MetaValues, context *qor.Context) (err error) {
if metaValues != nil {
return findOneHandler(value, metaValues, context)
}
if primaryKey := res.GetPrimaryValue(context.Request); primaryKey != "" {
parentValue := parent.NewStruct()
if parentValue, err = findParent(context); err == nil {
primaryQuerySQL, primaryParams := res.ToPrimaryQueryParams(primaryKey, context)
result := context.GetDB().Model(parentValue).Where(primaryQuerySQL, primaryParams...).Related(value)
if result.Error != nil {
err = result.Error
}
scope := gorm.Scope{Value: value}
if scope.PrimaryKeyZero() && result.RowsAffected == 0 {
err = gorm.ErrRecordNotFound
}
}
}
return
}
res.FindManyHandler = func(value interface{}, context *qor.Context) (err error) {
parentValue := parent.NewStruct()
if parentValue, err = findParent(context); err == nil {
if _, ok := context.GetDB().Get("qor:getting_total_count"); ok {
*(value.(*int)) = context.GetDB().Model(parentValue).Association(fieldName).Count()
return nil
}
return context.GetDB().Model(parentValue).Association(fieldName).Find(value).Error
}
return err
}
res.SaveHandler = func(value interface{}, context *qor.Context) (err error) {
parentValue := parent.NewStruct()
if parentValue, err = findParent(context); err == nil {
return context.GetDB().Model(parentValue).Association(fieldName).Append(value).Error
}
return err
}
res.DeleteHandler = func(value interface{}, context *qor.Context) (err error) {
if primaryKey := res.GetPrimaryValue(context.Request); primaryKey != "" {
primaryQuerySQL, primaryParams := res.ToPrimaryQueryParams(primaryKey, context)
if err = context.GetDB().Where(primaryQuerySQL, primaryParams...).First(value).Error; err == nil {
parentValue := parent.NewStruct()
if parentValue, err = findParent(context); err == nil {
return context.GetDB().Model(parentValue).Association(fieldName).Delete(value).Error
}
}
}
return
}
}
// Decode decode context into a value
func (res *Resource) Decode(context *qor.Context, value interface{}) error {
return resource.Decode(context, value, res)
}
func (res *Resource) allAttrs() []string {
var attrs []string
scope := &gorm.Scope{Value: res.Value}
Fields:
for _, field := range scope.GetModelStruct().StructFields {
for _, meta := range res.metas {
if field.Name == meta.FieldName {
attrs = append(attrs, meta.Name)
continue Fields
}
}
if field.IsForeignKey {
continue
}
for _, value := range []string{"CreatedAt", "UpdatedAt", "DeletedAt"} {
if value == field.Name {
continue Fields
}
}
if (field.IsNormal || field.Relationship != nil) && !field.IsIgnored {
attrs = append(attrs, field.Name)
continue
}
fieldType := field.Struct.Type
for fieldType.Kind() == reflect.Ptr || fieldType.Kind() == reflect.Slice {
fieldType = fieldType.Elem()
}
if fieldType.Kind() == reflect.Struct {
attrs = append(attrs, field.Name)
}
}
MetaIncluded:
for _, meta := range res.metas {
for _, attr := range attrs {
if attr == meta.FieldName || attr == meta.Name {
continue MetaIncluded
}
}
attrs = append(attrs, meta.Name)
}
return attrs
}
func (res *Resource) getAttrs(attrs []string) []string {
if len(attrs) == 0 {
return res.allAttrs()
}
var onlyExcludeAttrs = true
for _, attr := range attrs {
if !strings.HasPrefix(attr, "-") {
onlyExcludeAttrs = false
break
}
}
if onlyExcludeAttrs {
return append(res.allAttrs(), attrs...)
}
return attrs
}
// IndexAttrs set attributes will be shown in the index page
// // show given attributes in the index page
// order.IndexAttrs("User", "PaymentAmount", "ShippedAt", "CancelledAt", "State", "ShippingAddress")
// // show all attributes except `State` in the index page
// order.IndexAttrs("-State")
func (res *Resource) IndexAttrs(values ...interface{}) []*Section {
overriddingIndexAttrs := res.sections.OverriddingIndexAttrs
res.sections.OverriddingIndexAttrs = true
res.setSections(&res.sections.IndexSections, values...)
res.SearchAttrs()
// don't call callbacks when overridding
if !overriddingIndexAttrs {
for _, callback := range res.sections.OverriddingIndexAttrsCallbacks {
callback()
}
res.sections.OverriddingIndexAttrs = false
}
return res.sections.IndexSections
}
// OverrideIndexAttrs register function that will be run everytime index attrs changed
func (res *Resource) OverrideIndexAttrs(fc func()) {
overriddingIndexAttrs := res.sections.OverriddingIndexAttrs
res.sections.OverriddingIndexAttrs = true
res.sections.OverriddingIndexAttrsCallbacks = append(res.sections.OverriddingIndexAttrsCallbacks, fc)
fc()
if !overriddingIndexAttrs {
res.sections.OverriddingIndexAttrs = false
}
}
// NewAttrs set attributes will be shown in the new page
// // show given attributes in the new page
// order.NewAttrs("User", "PaymentAmount", "ShippedAt", "CancelledAt", "State", "ShippingAddress")
// // show all attributes except `State` in the new page
// order.NewAttrs("-State")
// You could also use `Section` to structure form to make it tidy and clean
// product.NewAttrs(
// &admin.Section{
// Title: "Basic Information",
// Rows: [][]string{
// {"Name"},
// {"Code", "Price"},
// }},
// &admin.Section{
// Title: "Organization",
// Rows: [][]string{
// {"Category", "Collections", "MadeCountry"},
// }},
// "Description",
// "ColorVariations",
// }
func (res *Resource) NewAttrs(values ...interface{}) []*Section {
overriddingNewAttrs := res.sections.OverriddingNewAttrs
res.sections.OverriddingNewAttrs = true
res.setSections(&res.sections.NewSections, values...)
// don't call callbacks when overridding
if !overriddingNewAttrs {
for _, callback := range res.sections.OverriddingNewAttrsCallbacks {
callback()
}
res.sections.OverriddingNewAttrs = false
}
return res.sections.NewSections
}
// OverrideNewAttrs register function that will be run everytime new attrs changed
func (res *Resource) OverrideNewAttrs(fc func()) {
overriddingNewAttrs := res.sections.OverriddingNewAttrs
res.sections.OverriddingNewAttrs = true
res.sections.OverriddingNewAttrsCallbacks = append(res.sections.OverriddingNewAttrsCallbacks, fc)
fc()
if !overriddingNewAttrs {
res.sections.OverriddingNewAttrs = false
}
}
// EditAttrs set attributes will be shown in the edit page
// // show given attributes in the new page
// order.EditAttrs("User", "PaymentAmount", "ShippedAt", "CancelledAt", "State", "ShippingAddress")
// // show all attributes except `State` in the edit page
// order.EditAttrs("-State")
// You could also use `Section` to structure form to make it tidy and clean
// product.EditAttrs(
// &admin.Section{
// Title: "Basic Information",
// Rows: [][]string{
// {"Name"},
// {"Code", "Price"},
// }},
// &admin.Section{
// Title: "Organization",
// Rows: [][]string{
// {"Category", "Collections", "MadeCountry"},
// }},
// "Description",
// "ColorVariations",
// }
func (res *Resource) EditAttrs(values ...interface{}) []*Section {
overriddingEditAttrs := res.sections.OverriddingEditAttrs
res.sections.OverriddingEditAttrs = true
res.setSections(&res.sections.EditSections, values...)
// don't call callbacks when overridding
if !overriddingEditAttrs {
for _, callback := range res.sections.OverriddingEditAttrsCallbacks {
callback()
}
res.sections.OverriddingEditAttrs = false
}
return res.sections.EditSections
}
// OverrideEditAttrs register function that will be run everytime edit attrs changed
func (res *Resource) OverrideEditAttrs(fc func()) {
overriddingEditAttrs := res.sections.OverriddingEditAttrs
res.sections.OverriddingEditAttrs = true
res.sections.OverriddingEditAttrsCallbacks = append(res.sections.OverriddingEditAttrsCallbacks, fc)
fc()
if !overriddingEditAttrs {
res.sections.OverriddingEditAttrs = false
}
}
// ShowAttrs set attributes will be shown in the show page
// // show given attributes in the show page
// order.ShowAttrs("User", "PaymentAmount", "ShippedAt", "CancelledAt", "State", "ShippingAddress")
// // show all attributes except `State` in the show page
// order.ShowAttrs("-State")
// You could also use `Section` to structure form to make it tidy and clean
// product.ShowAttrs(
// &admin.Section{
// Title: "Basic Information",
// Rows: [][]string{
// {"Name"},
// {"Code", "Price"},
// }},
// &admin.Section{
// Title: "Organization",
// Rows: [][]string{
// {"Category", "Collections", "MadeCountry"},
// }},
// "Description",
// "ColorVariations",
// }
func (res *Resource) ShowAttrs(values ...interface{}) []*Section {
overriddingShowAttrs := res.sections.OverriddingShowAttrs
settingShowAttrs := true
res.sections.OverriddingShowAttrs = true
if len(values) > 0 {
if values[len(values)-1] == false {
settingShowAttrs = false
values = values[:len(values)-1]
}
}
res.setSections(&res.sections.ShowSections, values...)
// don't call callbacks when overridding
if !overriddingShowAttrs {
if settingShowAttrs && len(values) > 0 {
res.sections.ConfiguredShowAttrs = true
}
for _, callback := range res.sections.OverriddingShowAttrsCallbacks {
callback()
}
res.sections.OverriddingShowAttrs = false
}
return res.sections.ShowSections
}
// OverrideShowAttrs register function that will be run everytime show attrs changed
func (res *Resource) OverrideShowAttrs(fc func()) {
overriddingShowAttrs := res.sections.OverriddingShowAttrs
res.sections.OverriddingShowAttrs = true
res.sections.OverriddingShowAttrsCallbacks = append(res.sections.OverriddingShowAttrsCallbacks, fc)
fc()
if !overriddingShowAttrs {
res.sections.OverriddingShowAttrs = false
}
}
// SortableAttrs set sortable attributes, sortable attributes are clickable to sort data in index page
func (res *Resource) SortableAttrs(columns ...string) []string {
if len(columns) != 0 || res.sections.SortableAttrs == nil {
if len(columns) == 0 {
columns = res.ConvertSectionToStrings(res.sections.IndexSections)
}
res.sections.SortableAttrs = &[]string{}
scope := res.GetAdmin().DB.NewScope(res.Value)
for _, column := range columns {
if field, ok := scope.FieldByName(column); ok && field.DBName != "" {
attrs := append(*res.sections.SortableAttrs, column)
res.sections.SortableAttrs = &attrs
}
}
}
return *res.sections.SortableAttrs
}
// SearchAttrs set searchable attributes, e.g:
// product.SearchAttrs("Name", "Code", "Category.Name", "Brand.Name")
// // Search products with its name, code, category's name, brand's name
func (res *Resource) SearchAttrs(columns ...string) []string {
if len(columns) != 0 || res.SearchHandler == nil {
if len(columns) == 0 {
columns = res.ConvertSectionToStrings(res.sections.IndexSections)
}
if len(columns) > 0 {
res.SearchHandler = func(keyword string, context *qor.Context) *gorm.DB {
var filterFields []filterField
for _, column := range columns {
filterFields = append(filterFields, filterField{FieldName: column})
}
return filterResourceByFields(res, filterFields, keyword, context.GetDB(), context)
}
}
}
return columns
}
// Meta register meta for admin resource
func (res *Resource) Meta(meta *Meta) *Meta {
if oldMeta := res.GetMeta(meta.Name); oldMeta != nil {
if meta.Type != "" {
oldMeta.Type = meta.Type
oldMeta.Config = nil
}
if meta.Label != "" {
oldMeta.Label = meta.Label
}
if meta.FieldName != "" {
oldMeta.FieldName = meta.FieldName
}
if meta.Setter != nil {
oldMeta.Setter = meta.Setter
}
if meta.Valuer != nil {
oldMeta.Valuer = meta.Valuer
}
if meta.FormattedValuer != nil {
oldMeta.FormattedValuer = meta.FormattedValuer
}
if meta.Resource != nil {
oldMeta.Resource = meta.Resource
}
if meta.Permission != nil {
oldMeta.Permission = meta.Permission
}
if meta.Config != nil {
oldMeta.Config = meta.Config
}
if meta.Collection != nil {
oldMeta.Collection = meta.Collection
}
meta = oldMeta
} else {
res.metas = append(res.metas, meta)
meta.baseResource = res
}
meta.configure()
return meta
}
// GetMetas get metas with give attrs
func (res *Resource) GetMetas(attrs []string) []resource.Metaor {
if len(attrs) == 0 {
attrs = res.allAttrs()
}
var showSections, ignoredAttrs []string
for _, attr := range attrs {
if strings.HasPrefix(attr, "-") {
ignoredAttrs = append(ignoredAttrs, strings.TrimLeft(attr, "-"))
} else {
showSections = append(showSections, attr)
}
}
metas := []resource.Metaor{}
Attrs:
for _, attr := range showSections {
for _, a := range ignoredAttrs {
if attr == a {
continue Attrs
}
}
var meta *Meta
for _, m := range res.metas {
if m.GetName() == attr {
meta = m
break
}
}
if meta == nil {
meta = &Meta{Name: attr, baseResource: res}
for _, primaryField := range res.PrimaryFields {
if attr == primaryField.Name {
meta.Type = "hidden_primary_key"
break
}
}
meta.configure()
}
metas = append(metas, meta)
}
return metas
}
// GetMeta get meta with name
func (res *Resource) GetMeta(name string) *Meta {
var fallbackMeta *Meta
for _, meta := range res.metas {
if meta.Name == name {
return meta
}
if meta.GetFieldName() == name {
fallbackMeta = meta
}
}
if fallbackMeta == nil {
if field, ok := res.GetAdmin().DB.NewScope(res.Value).FieldByName(name); ok {
meta := &Meta{Name: name, baseResource: res}
if field.IsPrimaryKey {
meta.Type = "hidden_primary_key"
}
meta.configure()
res.metas = append(res.metas, meta)
return meta
}
}
return fallbackMeta
}
func (res *Resource) allowedSections(sections []*Section, context *Context, roles ...roles.PermissionMode) []*Section {
var newSections []*Section
for _, section := range sections {
newSection := Section{Resource: section.Resource, Title: section.Title}
var editableRows [][]string
for _, row := range section.Rows {
var editableColumns []string
for _, column := range row {
for _, role := range roles {
meta := res.GetMeta(column)
if meta != nil && meta.HasPermission(role, context.Context) {
editableColumns = append(editableColumns, column)
break
}
}
}
if len(editableColumns) > 0 {
editableRows = append(editableRows, editableColumns)
}
}
newSection.Rows = editableRows
newSections = append(newSections, &newSection)
}
return newSections
}
func (res *Resource) configure() {
var configureModel func(value interface{})
configureModel = func(value interface{}) {
modelType := utils.ModelType(value)
if modelType.Kind() == reflect.Struct {
for i := 0; i < modelType.NumField(); i++ {
if fieldStruct := modelType.Field(i); fieldStruct.Anonymous {
if injector, ok := reflect.New(fieldStruct.Type).Interface().(resource.ConfigureResourceInterface); ok {
injector.ConfigureQorResource(res)
} else {
configureModel(reflect.New(fieldStruct.Type).Interface())
}
}
}
}
}
configureModel(res.Value)
scope := gorm.Scope{Value: res.Value}
for _, field := range scope.Fields() {
if field.StructField.Struct.Type.Kind() == reflect.Struct {
fieldData := reflect.New(field.StructField.Struct.Type).Interface()
_, configureMetaBeforeInitialize := fieldData.(resource.ConfigureMetaBeforeInitializeInterface)
_, configureMeta := fieldData.(resource.ConfigureMetaInterface)
if configureMetaBeforeInitialize || configureMeta {
res.Meta(&Meta{Name: field.Name})
}
}
}
if injector, ok := res.Value.(resource.ConfigureResourceInterface); ok {
injector.ConfigureQorResource(res)
}
}