func (b *BaseCondition) Evaluate(file *File) (bool, error) {
	fieldValue := file.GetField(b.Field)

	switch b.Operator {
	case Eq:
		return fieldValue == b.Value, nil
	case Neq:
		return fieldValue != b.Value, nil
	case StartsWith:
		return strings.HasPrefix(fieldValue.(string), b.Value), nil
	case NStartsWith:
		return !strings.HasPrefix(fieldValue.(string), b.Value), nil
	case EndsWith:
		return strings.HasSuffix(fieldValue.(string), b.Value), nil
	case NEndsWith:
		return !strings.HasSuffix(fieldValue.(string), b.Value), nil
	case Contains:
		return strings.Contains(fieldValue.(string), b.Value), nil
	case NContains:
		return !strings.Contains(fieldValue.(string), b.Value), nil
	case Gt:
		if num, ok := fieldValue.(float64); ok {
			f, err := strconv.ParseFloat(b.Value, 32)
			if err != nil {
				return false, errors.New("value in config is not a float")
			}
			return num > f, nil
		} else if date, ok := fieldValue.(time.Duration); ok {
			var dur time.Duration
			var err error
			dur, err = time.ParseDuration(b.Value)
			if err != nil {
				if strings.HasPrefix(err.Error(), "time: unknown unit d") {
					// Workaround to get "d" unit.
					intermed := strings.ReplaceAll(b.Value, "d", "h")
					dur, err = time.ParseDuration(intermed)
					if err != nil {
						return false, nil
					}
					dur = dur * time.Duration(24)
				} else {
					return false, err
				}
			}
			return date > dur, nil
		}
		return false, errors.New("unsupported operator")
	default:
		return false, fmt.Errorf("unsupported operator: %s", b.Operator)
	}
}
// Evaluate evaluates the condition.
Evaluate evaluates the condition.
// Evaluate evaluates the condition .
func (b *BaseCondition) Evaluate(file *File) (bool, error) {
	fieldValue := file.GetField(b.Field)
	switch b.Operator {
	case Eq:
		return fieldValue == b.Value, nil
	case Neq:
		return fieldValue != b.Value, nil
	case StartsWith:
		return strings.HasPrefix(fieldValue.(string), b.Value), nil
	case NStartsWith:
		return !strings.HasPrefix(fieldValue.(string), b.Value), nil
	case EndsWith:
		return strings.HasSuffix(fieldValue.(string), b.Value), nil
	case NEndsWith:
		return !strings.HasSuffix(fieldValue.(string), b.Value), nil
	case Contains:
		return strings.Contains(fieldValue.(string), b.Value), nil
	case NContains:
		return !strings.Contains(fieldValue.(string), b.Value), nil
	case Gt:
		if num, ok := fieldValue.(float64); ok {
			f, err := strconv.ParseFloat(b.Value, 32)
			if err != nil {
				return false, errors.New("value in config is not a float")
			}
			return num > f, nil
		} else if date, ok := fieldValue.(time.Duration); ok {
			var dur time.Duration
			var err error
			dur, err = time.ParseDuration(b.Value)
			if err != nil {
				if strings.HasPrefix(err.Error(), "time: unknown unit d") {
					intermed := strings.ReplaceAll(b.Value, "d", "h")
					dur, err = time.ParseDuration(intermed)
					if err != nil {
						return false, nil
					}
					dur = dur * time.Duration(24)
				} else {
					return false, err
				}
			}
			return date > dur, nil
		}
		return false, errors.New("unsupported operator")
	default:
		return false, fmt.Errorf("unsupported operator: %s", b.Operator)
	}
}
func ( b * BaseCondition ) Evaluate ( file * File ) ( bool , error ) { fieldValue := file . GetField ( b . Field ) switch b . Operator { case Eq : return fieldValue == b . Value , nil case Neq : return fieldValue != b . Value , nil case StartsWith : return strings . HasPrefix ( fieldValue . ( string ) , b . Value ) , nil case NStartsWith : return ! strings . HasPrefix ( fieldValue . ( string ) , b . Value ) , nil case EndsWith : return strings . HasSuffix ( fieldValue . ( string ) , b . Value ) , nil case NEndsWith : return ! strings . HasSuffix ( fieldValue . ( string ) , b . Value ) , nil case Contains : return strings . Contains ( fieldValue . ( string ) , b . Value ) , nil case NContains : return ! strings . Contains ( fieldValue . ( string ) , b . Value ) , nil case Gt : if num , ok := fieldValue . ( float64 ) ; ok { f , err := strconv . ParseFloat ( b . Value , 32 ) if err != nil { return false , errors . New ( " " ) } return num > f , nil } else if date , ok := fieldValue . ( time . Duration ) ; ok { var dur time . Duration var err error dur , err = time . ParseDuration ( b . Value ) if err != nil { if strings . HasPrefix ( err . Error ( ) , " " ) { intermed := strings . ReplaceAll ( b . Value , " " , " " ) dur , err = time . ParseDuration ( intermed ) if err != nil { return false , nil } dur = dur * time . Duration ( 24 ) } else { return false , err } } return date > dur , nil } return false , errors . New ( " " ) default : return false , fmt . Errorf ( " " , b . Operator ) } }
Evaluate evaluates the condition.
Evaluate evaluates the condition .
// Workaround to get "d" unit.