mattermost-community-enterp.../vendor/github.com/splitio/go-split-commons/v7/engine/grammar/between.go
Claude ec1f89217a Merge: Complete Mattermost Server with Community Enterprise
Full Mattermost server source with integrated Community Enterprise features.
Includes vendor directory for offline/air-gapped builds.

Structure:
- enterprise-impl/: Enterprise feature implementations
- enterprise-community/: Init files that register implementations
- enterprise/: Bridge imports (community_imports.go)
- vendor/: All dependencies for offline builds

Build (online):
  go build ./cmd/mattermost

Build (offline/air-gapped):
  go build -mod=vendor ./cmd/mattermost

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-17 23:59:07 +09:00

72 lines
2.1 KiB
Go

package grammar
import (
"fmt"
"reflect"
"github.com/splitio/go-split-commons/v7/engine/grammar/datatypes"
)
// BetweenMatcher will match if two numbers or two datetimes are equal
type BetweenMatcher struct {
Matcher
ComparisonDataType string
LowerComparisonValue int64
UpperComparisonValue int64
}
// Match will match if the matchingValue is between lowerComparisonValue and upperComparisonValue
func (m *BetweenMatcher) Match(key string, attributes map[string]interface{}, bucketingKey *string) bool {
matchingRaw, err := m.matchingKey(key, attributes)
if err != nil {
m.logger.Warning(fmt.Sprintf("BetweenMatcher: %s", err.Error()))
return false
}
var matchingValue int64
matchingValue, okMatching := matchingRaw.(int64)
if !okMatching {
var asInt int
asInt, okMatching = matchingRaw.(int)
if okMatching {
matchingValue = int64(asInt)
}
}
if !okMatching {
m.logger.Error(
"BetweenMatcher: Could not parse attribute to an int. ",
fmt.Sprintf("Attribute is of type %s\n", reflect.TypeOf(matchingRaw).String()),
)
return false
}
var comparisonLower int64
var comparisonUpper int64
switch m.ComparisonDataType {
case datatypes.Number:
comparisonLower = m.LowerComparisonValue
comparisonUpper = m.UpperComparisonValue
case datatypes.Datetime:
matchingValue = datatypes.ZeroSecondsTS(matchingValue)
comparisonLower = datatypes.ZeroSecondsTS(datatypes.TsFromJava(m.LowerComparisonValue))
comparisonUpper = datatypes.ZeroSecondsTS(datatypes.TsFromJava(m.UpperComparisonValue))
default:
m.base().logger.Error(fmt.Sprintf("BetweenMatcher: Incorrect type %s", m.ComparisonDataType))
return false
}
return matchingValue >= comparisonLower && matchingValue <= comparisonUpper
}
// NewBetweenMatcher returns a pointer to a new instance of BetweenMatcher
func NewBetweenMatcher(negate bool, lower int64, upper int64, cmpType string, attributeName *string) *BetweenMatcher {
return &BetweenMatcher{
Matcher: Matcher{
negate: negate,
attributeName: attributeName,
},
LowerComparisonValue: lower,
UpperComparisonValue: upper,
ComparisonDataType: cmpType,
}
}