pattern

package
v0.0.0-...-9b5cd94 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2024 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package pattern provides functionality for filtering and matching models.

Index

Constants

View Source
const (
	ConditionEqual        = "eq"
	ConditionNotEqual     = "neq"
	ConditionGT           = "gt"
	ConditionLT           = "lt"
	ConditionRegexp       = "regexp"
	ConditionContain      = "contain"
	ConditionNotContain   = "not_contain"
	ConditionBeginWith    = "begin_with"
	ConditionNotBeginWith = "not_begin_with"
	ConditionEndWith      = "end_with"
	ConditionNotEndWith   = "not_end_with"
	ConditionHasEvery     = "has_every"
	ConditionHasOneOf     = "has_one_of"
	ConditionHasNot       = "has_not"
	ConditionIsEmpty      = "is_empty"
	ConditionExist        = "exist"
	ConditionTimeRelative = "relative_time"
	ConditionTimeAbsolute = "absolute_time"
	ConditionIsOneOf      = "is_one_of"
	ConditionIsNotOneOf   = "is_not_one_of"
)
View Source
const (
	FieldTypeString      = "string"
	FieldTypeInt         = "int"
	FieldTypeBool        = "bool"
	FieldTypeStringArray = "string_array"
)

Variables

View Source
var ErrOverwriteMatchedRegexp = errors.New("attempt to overwrite matched regex with groups")
View Source
var ErrUnsupportedConditionType = errors.New("unsupported condition type")
View Source
var ErrUnsupportedField = errors.New("unsupported field")
View Source
var ErrWrongConditionValue = errors.New("wrong condition value")

Functions

func GetAlarmInfoName

func GetAlarmInfoName(f string) string

func GetBoolValue

func GetBoolValue(v interface{}) (bool, error)

func GetEntityComponentInfoName

func GetEntityComponentInfoName(f string) string

func GetEntityInfoName

func GetEntityInfoName(f string) string

func GetEventExtraInfoName

func GetEventExtraInfoName(f string) string

func GetIntValue

func GetIntValue(v interface{}) (int64, error)

func GetStringArrayValue

func GetStringArrayValue(v interface{}) ([]string, error)

func GetStringValue

func GetStringValue(v interface{}) (string, error)

func IsForbiddenAlarmField

func IsForbiddenAlarmField(condition FieldCondition, forbiddenFieldsMap map[string]bool, timeAbsoluteFieldsMap map[string]bool) bool

func IsForbiddenEntityField

func IsForbiddenEntityField(condition FieldCondition, forbiddenFieldsMap map[string]bool) bool

Types

type Alarm

type Alarm [][]FieldCondition

func (Alarm) GetMongoFields

func (p Alarm) GetMongoFields(prefix string) bson.M

func (Alarm) HasField

func (p Alarm) HasField(field string) bool

func (Alarm) HasInfosField

func (p Alarm) HasInfosField() bool

func (Alarm) RemoveFields

func (p Alarm) RemoveFields(fields, onlyTimeAbsoluteFields []string) Alarm

type Condition

type Condition struct {
	Type  string      `json:"type" bson:"type"`
	Value interface{} `json:"value" bson:"value"`
	// contains filtered or unexported fields
}

Condition represents an expression to decide if a value fits.

func NewBoolCondition

func NewBoolCondition(t string, b bool) Condition

func NewDurationCondition

func NewDurationCondition(t string, d datetime.DurationWithUnit) (Condition, error)

func NewIntCondition

func NewIntCondition(t string, i int64) Condition

func NewRegexpCondition

func NewRegexpCondition(t, s string) (Condition, error)

func NewStringArrayCondition

func NewStringArrayCondition(t string, a []string) Condition

func NewStringCondition

func NewStringCondition(t, s string) Condition

func NewTimeIntervalCondition

func NewTimeIntervalCondition(t string, from, to int64) Condition

func (*Condition) BoolToMongoQuery

func (c *Condition) BoolToMongoQuery(f string) (bson.M, error)

func (*Condition) BoolToSql

func (c *Condition) BoolToSql(f string) (string, error)

func (*Condition) BoolToSqlJson

func (c *Condition) BoolToSqlJson(field, key string) (string, error)

func (*Condition) DurationToMongoQuery

func (c *Condition) DurationToMongoQuery(f string) (bson.M, error)

func (*Condition) DurationToSql

func (c *Condition) DurationToSql(f string) (string, error)

func (*Condition) GetRegexp

func (c *Condition) GetRegexp() utils.RegexExpression

func (*Condition) GetValueStr

func (c *Condition) GetValueStr() *string

func (*Condition) GetValueStrArray

func (c *Condition) GetValueStrArray() []string

func (*Condition) IntToMongoQuery

func (c *Condition) IntToMongoQuery(f string, checkExists bool) (bson.M, error)

func (*Condition) IntToSql

func (c *Condition) IntToSql(f string) (string, error)

func (*Condition) IntToSqlJson

func (c *Condition) IntToSqlJson(field, key string) (string, error)

func (*Condition) MatchBool

func (c *Condition) MatchBool(value bool) (bool, error)

func (*Condition) MatchDuration

func (c *Condition) MatchDuration(value int64) (bool, error)

func (*Condition) MatchInt

func (c *Condition) MatchInt(value int64) (bool, error)

func (*Condition) MatchRef

func (c *Condition) MatchRef(value interface{}) (bool, error)

func (*Condition) MatchString

func (c *Condition) MatchString(value string) (bool, error)

func (*Condition) MatchStringArray

func (c *Condition) MatchStringArray(value []string) (bool, error)

func (*Condition) MatchStringWithRegexpMatches

func (c *Condition) MatchStringWithRegexpMatches(value string) (bool, RegexMatches, error)

func (*Condition) MatchTime

func (c *Condition) MatchTime(value time.Time) (bool, error)

func (*Condition) RefToMongoQuery

func (c *Condition) RefToMongoQuery(f string) (bson.M, error)

func (*Condition) RefToSqlJson

func (c *Condition) RefToSqlJson(field, key string) (string, error)

func (*Condition) StringArrayToMongoQuery

func (c *Condition) StringArrayToMongoQuery(f string, checkExists bool) (bson.M, error)

func (*Condition) StringArrayToSqlJson

func (c *Condition) StringArrayToSqlJson(field, key string) (string, error)

func (*Condition) StringToMongoQuery

func (c *Condition) StringToMongoQuery(f string, checkExists bool) (bson.M, error)

func (*Condition) StringToSql

func (c *Condition) StringToSql(f string) (string, error)

func (*Condition) StringToSqlJson

func (c *Condition) StringToSqlJson(field, key string) (string, error)

func (*Condition) TimeToMongoQuery

func (c *Condition) TimeToMongoQuery(f string) (bson.M, error)

func (*Condition) UnmarshalBSONValue

func (c *Condition) UnmarshalBSONValue(_ bsontype.Type, b []byte) error

func (*Condition) UnmarshalJSON

func (c *Condition) UnmarshalJSON(b []byte) error

type Entity

type Entity [][]FieldCondition

func (Entity) RemoveFields

func (p Entity) RemoveFields(fields []string) Entity

type Event

type Event [][]FieldCondition

func (Event) HasExtraInfosField

func (p Event) HasExtraInfosField() bool

func (Event) HasField

func (p Event) HasField(field string) bool

type FieldCondition

type FieldCondition struct {
	Field string `json:"field" bson:"field"`
	// FieldType is only defined for custom fields, ex: infos.
	FieldType string    `json:"field_type,omitempty" bson:"field_type,omitempty"`
	Condition Condition `json:"cond" bson:"cond"`
}

FieldCondition represents a condition for a specific field.

func (*FieldCondition) MatchInfoCondition

func (c *FieldCondition) MatchInfoCondition(infoVal any, infoExists bool) (bool, error)

MatchInfoCondition is a helper function to match FieldCondition when it's used to match various infos fields.

func (*FieldCondition) ValidateInfoCondition

func (c *FieldCondition) ValidateInfoCondition() bool

ValidateInfoCondition is a helper function to validate FieldCondition when it's used to match various infos fields.

type PbehaviorInfo

type PbehaviorInfo [][]FieldCondition

type RegexMatches

type RegexMatches map[string]string

RegexMatches is a type that contains the values of the sub-expressions of a regular expression.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL