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 }
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, ", ")) }