Ejemplo n.º 1
0
// Read analyzes a given key/value map to extract the configuration values valid
// for each plugin. All non-default values are written to the Settings member.
func (conf *PluginConfig) Read(values shared.MarshalMap) {
	var err error
	for key, settingValue := range values {
		switch key {
		case "ID":
			conf.ID, err = values.String("ID")

		case "Enable":
			conf.Enable, err = values.Bool("Enable")

		case "Instances":
			conf.Instances, err = values.Int("Instances")

		case "Stream":
			conf.Stream, err = values.StringArray("Stream")

		default:
			conf.Settings[key] = settingValue
		}
		if err != nil {
			Log.Error.Fatalf(err.Error())
		}
	}

	// Sanity checks
	if conf.Instances == 0 {
		conf.Enable = false
	}
	if len(conf.Stream) == 0 {
		conf.Stream = append(conf.Stream, "*")
	}
}
Ejemplo n.º 2
0
func (filter *JSON) getValue(key string, values shared.MarshalMap) (string, bool) {
	if value, found := values.Path(key); found {
		switch value.(type) {
		case string:
			return value.(string), true

		case bool:
			return strconv.FormatBool(value.(bool)), true

		case float64:
			return strconv.FormatFloat(value.(float64), 'f', -1, 64), true
		}
	}

	return "", false
}