-
Notifications
You must be signed in to change notification settings - Fork 2
/
include_loader.go
42 lines (33 loc) · 1.08 KB
/
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
42
package goen
import (
"container/list"
"context"
"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(ctx context.Context, later *IncludeBuffer, sc *ScopeCache, records interface{}) error
}
type IncludeLoaderFunc func(context.Context, *IncludeBuffer, *ScopeCache, interface{}) error
func (fn IncludeLoaderFunc) Load(ctx context.Context, later *IncludeBuffer, sc *ScopeCache, records interface{}) error {
return fn(ctx, later, sc, records)
}
type IncludeLoaderList []IncludeLoader
func (list *IncludeLoaderList) Append(v ...IncludeLoader) {
*list = append(*list, v...)
}
func (list IncludeLoaderList) Load(ctx context.Context, later *IncludeBuffer, sc *ScopeCache, records interface{}) error {
for _, loader := range list {
if err := loader.Load(ctx, later, sc, records); err != nil {
return err
}
}
return nil
}