-
Notifications
You must be signed in to change notification settings - Fork 2
/
include_loader.go
41 lines (32 loc) · 1006 Bytes
/
include_loader.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
package goen
import (
"container/list"
"reflect"
)
type IncludeBuffer list.List
func (l *IncludeBuffer) AddRecords(records interface{}) {
typ := reflect.TypeOf(records)
if typ.Kind() != reflect.Slice {
panic("goen: AddRecords only accepts a slice of entities, not " + typ.String())
}
(*list.List)(l).PushBack(records)
}
type IncludeLoader interface {
Load(later *IncludeBuffer, sc *ScopeCache, records interface{}) error
}
type IncludeLoaderFunc func(*IncludeBuffer, *ScopeCache, interface{}) error
func (fn IncludeLoaderFunc) Load(later *IncludeBuffer, sc *ScopeCache, records interface{}) error {
return fn(later, sc, records)
}
type IncludeLoaderList []IncludeLoader
func (list *IncludeLoaderList) Append(v ...IncludeLoader) {
*list = append(*list, v...)
}
func (list IncludeLoaderList) Load(later *IncludeBuffer, sc *ScopeCache, records interface{}) error {
for _, loader := range list {
if err := loader.Load(later, sc, records); err != nil {
return err
}
}
return nil
}