| 383 | } |
| 384 | |
| 385 | func (this *Rule) Test(value any) bool { |
| 386 | // operator |
| 387 | switch this.Operator { |
| 388 | case RuleOperatorGt: |
| 389 | return types.Float64(value) > this.floatValue |
| 390 | case RuleOperatorGte: |
| 391 | return types.Float64(value) >= this.floatValue |
| 392 | case RuleOperatorLt: |
| 393 | return types.Float64(value) < this.floatValue |
| 394 | case RuleOperatorLte: |
| 395 | return types.Float64(value) <= this.floatValue |
| 396 | case RuleOperatorEq: |
| 397 | return types.Float64(value) == this.floatValue |
| 398 | case RuleOperatorNeq: |
| 399 | return types.Float64(value) != this.floatValue |
| 400 | case RuleOperatorEqString: |
| 401 | if this.IsCaseInsensitive { |
| 402 | return strings.EqualFold(this.stringifyValue(value), this.Value) |
| 403 | } else { |
| 404 | return this.stringifyValue(value) == this.Value |
| 405 | } |
| 406 | case RuleOperatorNeqString: |
| 407 | if this.IsCaseInsensitive { |
| 408 | return !strings.EqualFold(this.stringifyValue(value), this.Value) |
| 409 | } else { |
| 410 | return this.stringifyValue(value) != this.Value |
| 411 | } |
| 412 | case RuleOperatorMatch, RuleOperatorWildcardMatch: |
| 413 | if value == nil { |
| 414 | value = "" |
| 415 | } |
| 416 | |
| 417 | // strings |
| 418 | stringList, ok := value.([]string) |
| 419 | if ok { |
| 420 | for _, s := range stringList { |
| 421 | if utils.MatchStringCache(this.reg, s, this.cacheLife) { |
| 422 | return true |
| 423 | } |
| 424 | } |
| 425 | return false |
| 426 | } |
| 427 | |
| 428 | // bytes list |
| 429 | byteSlices, ok := value.([][]byte) |
| 430 | if ok { |
| 431 | for _, byteSlice := range byteSlices { |
| 432 | if utils.MatchBytesCache(this.reg, byteSlice, this.cacheLife) { |
| 433 | return true |
| 434 | } |
| 435 | } |
| 436 | return false |
| 437 | } |
| 438 | |
| 439 | // bytes |
| 440 | byteSlice, ok := value.([]byte) |
| 441 | if ok { |
| 442 | return utils.MatchBytesCache(this.reg, byteSlice, this.cacheLife) |