3 // configTree represents a tree of configurations where the root is the
4 // first file and its children are the configurations it has imported.
5 type configTree struct {
11 // Flatten flattens the entire tree down to a single merged Config
13 func (t *configTree) Flatten() (*Config, error) {
14 // No children is easy: we're already merged!
15 if len(t.Children) == 0 {
19 // Depth-first, merge all the children first.
20 childConfigs := make([]*Config, len(t.Children))
21 for i, ct := range t.Children {
22 c, err := ct.Flatten()
30 // Merge all the children in order
31 config := childConfigs[0]
32 childConfigs = childConfigs[1:]
33 for _, config2 := range childConfigs {
35 config, err = Merge(config, config2)
41 // Merge the final merged child config with our own
42 return Merge(config, t.Config)