Пример #1
0
func (f includeFields) Run(event common.MapStr) (common.MapStr, error) {
	filtered := common.MapStr{}
	errs := []string{}

	for _, field := range f.Fields {
		err := event.CopyFieldsTo(filtered, field)
		// Ignore errors caused by a field not existing in the event.
		if err != nil && errors.Cause(err) != common.ErrKeyNotFound {
			errs = append(errs, err.Error())
		}
	}

	return filtered, fmt.Errorf(strings.Join(errs, ", "))
}
Пример #2
0
func (f includeFields) Run(event common.MapStr) (common.MapStr, error) {
	filtered := common.MapStr{}

	for _, field := range f.Fields {
		hasKey, err := event.HasKey(field)
		if err != nil {
			return filtered, fmt.Errorf("Fail to check the key %s: %s", field, err)
		}

		if hasKey {
			errorOnCopy := event.CopyFieldsTo(filtered, field)
			if errorOnCopy != nil {
				return filtered, fmt.Errorf("Fail to copy key %s: %s", field, err)
			}
		}
	}

	return filtered, nil
}
Пример #3
0
func (f includeFields) Run(event common.MapStr) (common.MapStr, error) {
	filtered := common.MapStr{}
	errors := []string{}

	for _, field := range f.Fields {
		hasKey, err := event.HasKey(field)
		if err != nil {
			errors = append(errors, err.Error())
		}

		if hasKey {
			errorOnCopy := event.CopyFieldsTo(filtered, field)
			if errorOnCopy != nil {
				errors = append(errors, err.Error())
			}
		}
	}

	return filtered, fmt.Errorf(strings.Join(errors, ", "))
}