Skip to content

Commit

Permalink
Dont append to slices in mergeStruct
Browse files Browse the repository at this point in the history
  • Loading branch information
sparrc committed Nov 18, 2015
1 parent 19e5d97 commit 0ed7755
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 23 deletions.
6 changes: 1 addition & 5 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,7 @@ func (a *Agent) LoadPlugins(filters []string, config *Config) ([]string, error)

for name, plugin := range config.PluginsDeclared() {
if sliceContains(name, filters) || len(filters) == 0 {
config, err := config.ApplyPlugin(name, plugin)
if err != nil {
return nil, err
}

config := config.GetPluginConfig(name)
a.plugins = append(a.plugins, &runningPlugin{name, plugin, config})
names = append(names, name)
}
Expand Down
26 changes: 8 additions & 18 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,8 @@ func (c *Config) ApplyAgent(a *Agent) error {
return nil
}

// ApplyPlugin loads the Plugin struct built from the config into the given Plugin struct.
// Overrides only values in the given struct that were set in the config.
// Additionally return a ConfiguredPlugin, which is always generated from the config.
func (c *Config) ApplyPlugin(name string, v interface{}) (*ConfiguredPlugin, error) {
if c.plugins[name] != nil {
err := mergeStruct(v, c.plugins[name], c.pluginFieldsSet[name])
if err != nil {
return nil, err
}
return c.pluginConfigurations[name], nil
}

return nil, nil
func (c *Config) GetPluginConfig(name string) *ConfiguredPlugin {
return c.pluginConfigurations[name]
}

// Couldn't figure out how to get this to work with the declared function.
Expand Down Expand Up @@ -405,11 +394,12 @@ func mergeStruct(base, overlay interface{}, fields []string) error {
overlayValue.Type(), field)
}
baseFieldValue := findField(field, baseValue)
if overlayFieldValue.Kind() == reflect.Slice {
baseFieldValue.Set(reflect.AppendSlice(baseFieldValue, overlayFieldValue))
} else {
baseFieldValue.Set(overlayFieldValue)
}
baseFieldValue.Set(overlayFieldValue)
// if overlayFieldValue.Kind() == reflect.Slice {
// baseFieldValue.Set(reflect.AppendSlice(baseFieldValue, overlayFieldValue))
// } else {
// baseFieldValue.Set(overlayFieldValue)
// }
}
return nil
}
Expand Down

0 comments on commit 0ed7755

Please sign in to comment.