-
Notifications
You must be signed in to change notification settings - Fork 14
/
required_hydrate_calls.go
49 lines (40 loc) · 1.35 KB
/
required_hydrate_calls.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
package plugin
import (
"github.com/turbot/go-kit/helpers"
)
// helper class to build list of required hydrate calls
type requiredHydrateCallBuilder struct {
fetchCallName string
requiredHydrateCalls map[string]*HydrateCall
table *Table
}
func newRequiredHydrateCallBuilder(t *Table, fetchCallName string) *requiredHydrateCallBuilder {
return &requiredHydrateCallBuilder{
table: t,
fetchCallName: fetchCallName,
requiredHydrateCalls: make(map[string]*HydrateCall),
}
}
func (c requiredHydrateCallBuilder) Add(hydrateFunc HydrateFunc) {
hydrateName := helpers.GetFunctionName(hydrateFunc)
// if the resolved hydrate call is NOT the same as the fetch call, add to the map of hydrate functions to call
if hydrateName != c.fetchCallName {
if _, ok := c.requiredHydrateCalls[hydrateName]; ok {
return
}
// get the config for this hydrate function
config := c.table.hydrateConfigMap[hydrateName]
c.requiredHydrateCalls[hydrateName] = newHydrateCall(hydrateFunc, config)
// now add dependencies (we have already checked for circular dependencies so recursion is fine
for _, dep := range config.Depends {
c.Add(dep)
}
}
}
func (c requiredHydrateCallBuilder) Get() []*HydrateCall {
var res []*HydrateCall
for _, call := range c.requiredHydrateCalls {
res = append(res, call)
}
return res
}