Skip to content

Commit 00cfdc6

Browse files
committed
nomadVar: return map values instead of pointers when reading map items
1 parent 50f042b commit 00cfdc6

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

template/nomad_funcs.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,30 +82,31 @@ func nomadServiceFunc(b *Brain, used, missing *dep.Set) func(...interface{}) ([]
8282

8383
// nomadVariableItemsFunc returns a given variable rooted at the
8484
// items map.
85-
func nomadVariableItemsFunc(b *Brain, used, missing *dep.Set, defaultNS string) func(string) (*dep.NomadVarItems, error) {
86-
return func(s string) (*dep.NomadVarItems, error) {
85+
func nomadVariableItemsFunc(b *Brain, used, missing *dep.Set, defaultNS string) func(string) (dep.NomadVarItems, error) {
86+
return func(s string) (dep.NomadVarItems, error) {
8787
if len(s) == 0 {
88-
return nil, nil
88+
return dep.NomadVarItems(nil), nil
8989
}
9090

9191
d, err := dep.NewNVGetQuery(defaultNS, s)
9292
if err != nil {
93-
return nil, err
93+
return dep.NomadVarItems(nil), err
9494
}
9595
d.EnableBlocking()
9696

9797
used.Add(d)
9898

9999
if value, ok := b.Recall(d); ok {
100100
if value == nil {
101-
return nil, nil
101+
return dep.NomadVarItems(nil), nil
102102
}
103-
return value.(*dep.NomadVarItems), nil
103+
// Stored values in the Brain are pointers to NomadVarItems; return a value
104+
return *value.(*dep.NomadVarItems), nil
104105
}
105106

106107
missing.Add(d)
107108

108-
return nil, nil
109+
return dep.NomadVarItems(nil), nil
109110
}
110111
}
111112

0 commit comments

Comments
 (0)