Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Removed a useless UnmarshalJSON method
Browse files Browse the repository at this point in the history
This method was doing nothing more than `json.Unmarshal`.
  • Loading branch information
kindermoumoute committed Dec 16, 2016
1 parent 708da9f commit 3e2dd25
Showing 1 changed file with 0 additions and 65 deletions.
65 changes: 0 additions & 65 deletions control/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,71 +152,6 @@ func GetDefaultConfig() *Config {
}
}

// UnmarshalJSON unmarshals valid json into a Config. An example Config can be found
// at github.com/intelsdi-x/snap/blob/master/examples/configs/snap-config-sample.json
func (c *Config) UnmarshalJSON(data []byte) error {
// construct a map of strings to json.RawMessages (to defer the parsing of individual
// fields from the unmarshalled interface until later) and unmarshal the input
// byte array into that map
t := make(map[string]json.RawMessage)
if err := json.Unmarshal(data, &t); err != nil {
return err
}
// loop through the individual map elements, parse each in turn, and set
// the appropriate field in this configuration
for k, v := range t {
switch k {
case "max_running_plugins":
if err := json.Unmarshal(v, &(c.MaxRunningPlugins)); err != nil {
return fmt.Errorf("%v (while parsing 'control::max_running_plugins')", err)
}
case "plugin_load_timeout":
if err := json.Unmarshal(v, &(c.PluginLoadTimeout)); err != nil {
return fmt.Errorf("%v (while parsing 'control::plugin_load_timeout')", err)
}
case "plugin_trust_level":
if err := json.Unmarshal(v, &(c.PluginTrust)); err != nil {
return fmt.Errorf("%v (while parsing 'control::plugin_trust_level')", err)
}
case "auto_discover_path":
if err := json.Unmarshal(v, &(c.AutoDiscoverPath)); err != nil {
return fmt.Errorf("%v (while parsing 'control::auto_discover_path')", err)
}
case "keyring_paths":
if err := json.Unmarshal(v, &(c.KeyringPaths)); err != nil {
return fmt.Errorf("%v (while parsing 'control::keyring_paths')", err)
}
case "cache_expiration":
if err := json.Unmarshal(v, &(c.CacheExpiration)); err != nil {
return fmt.Errorf("%v (while parsing 'control::cache_expiration')", err)
}
case "plugins":
if err := json.Unmarshal(v, c.Plugins); err != nil {
return err
}
case "listen_addr":
if err := json.Unmarshal(v, &(c.ListenAddr)); err != nil {
return err
}
case "listen_port":
if err := json.Unmarshal(v, &(c.ListenPort)); err != nil {
return err
}
case "pprof":
if err := json.Unmarshal(v, &(c.Pprof)); err != nil {
return err
}
case "max_plugin_restarts":
if err := json.Unmarshal(v, &(c.MaxPluginRestarts)); err != nil {
return err
}
default:
return fmt.Errorf("Unrecognized key '%v' in global config file while parsing 'control'", k)
}
}
return nil
}

// NewPluginsConfig returns a map of *pluginConfigItems where the key is the plugin name.
func NewPluginsConfig() map[string]*pluginConfigItem {
return map[string]*pluginConfigItem{}
Expand Down

0 comments on commit 3e2dd25

Please sign in to comment.