Files
wehub-resource-sync 498b235461
Build and test / Build and test AMD64 Ubuntu 22.04 (push) Failing after 0s
Publish Builder / amazonlinux2023 (push) Failing after 1s
Build and test / UT for Go (push) Has been skipped
Publish KRTE Images / KRTE (push) Failing after 1s
Build and test / Integration Test (push) Has been skipped
Build and test / Upload Code Coverage (push) Has been skipped
Publish Builder / rockylinux9 (push) Failing after 1s
Publish Builder / ubuntu22.04 (push) Failing after 0s
Publish Builder / ubuntu24.04 (push) Failing after 0s
Publish Gpu Builder / publish-gpu-builder (push) Failing after 1s
Publish Test Images / PyTest (push) Failing after 0s
Build and test / UT for Cpp (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:31:17 +08:00

74 lines
1.3 KiB
Go

package predicates
// PredicateTarget is enum for Predicate target type.
type PredicateTarget int32
const (
// PredTargetValue is predicate target for key-value perid
PredTargetValue PredicateTarget = iota + 1
)
type PredicateType int32
const (
PredTypeEqual PredicateType = iota + 1
)
// Predicate provides interface for kv predicate.
type Predicate interface {
Target() PredicateTarget
Type() PredicateType
IsTrue(any) bool
Key() string
TargetValue() any
}
type valuePredicate struct {
k, v string
pt PredicateType
}
func (p *valuePredicate) Target() PredicateTarget {
return PredTargetValue
}
func (p *valuePredicate) Type() PredicateType {
return p.pt
}
func (p *valuePredicate) IsTrue(target any) bool {
switch v := target.(type) {
case string:
return predicateValue(p.pt, v, p.v)
case []byte:
return predicateValue(p.pt, string(v), p.v)
default:
return false
}
}
func (p *valuePredicate) Key() string {
return p.k
}
func (p *valuePredicate) TargetValue() any {
return p.v
}
func predicateValue[T comparable](pt PredicateType, v1, v2 T) bool {
switch pt {
case PredTypeEqual:
return v1 == v2
default:
return false
}
}
func ValueEqual(k, v string) Predicate {
return &valuePredicate{
k: k,
v: v,
pt: PredTypeEqual,
}
}