xfilter

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: May 2, 2025 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

xfilter

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assert

func Assert(ctx *Context, rule string) error

Assert filter 规则断言

func Filter

func Filter(ctx *Context, list []map[string]interface{}) ([]map[string]interface{}, error)

Filter 列表数据过滤

func ParseFilter

func ParseFilter(rule string) ([]interface{}, error)

ParseFilter 解析 filter 规则

Types

type Condition

type Condition interface {
	Name() string          // 条件描述
	Assert(*Context) error // 条件断言
}

Condition 断言条件接口

func NewCondition

func NewCondition(filters []interface{}) (Condition, error)

NewCondition 初始化复合条件

func NewConditionGroup

func NewConditionGroup(filters []interface{}) (Condition, error)

NewConditionGroup 初始化群组条件实例

type ConditionGroup

type ConditionGroup struct {
	Logic      Logic
	Conditions []Condition
}

ConditionGroup 群组条件, 包含 Logic 关系

func (*ConditionGroup) Assert

func (t *ConditionGroup) Assert(ctx *Context) (err error)

Assert ...

func (*ConditionGroup) Name

func (t *ConditionGroup) Name() string

Name ...

type ConditionSingle

type ConditionSingle struct {
	Variable  Variable    // 变量
	Operation Operation   // 操作符
	Expect    interface{} // 预期结果
}

ConditionSingle 单个条件

func NewConditionSingle

func NewConditionSingle(filter []interface{}) (*ConditionSingle, error)

NewConditionSingle 初始化单个条件实例

func (*ConditionSingle) Assert

func (t *ConditionSingle) Assert(ctx *Context) error

Assert ...

func (*ConditionSingle) Name

func (t *ConditionSingle) Name() string

Name ...

type Context

type Context struct {
	// contains filtered or unexported fields
}

Context filter 上下文

func NewContext

func NewContext(ctxs ...context.Context) *Context

NewContext ...

func (*Context) Ctx

func (t *Context) Ctx(k string) interface{}

Ctx 读取 ctx 数据

func (*Context) Get

func (t *Context) Get(k string) (interface{}, bool)

Get 读取数据

func (*Context) Set

func (t *Context) Set(k string, v interface{})

Set 写入数据

type Logic

type Logic string

Logic 条件组逻辑关系

const (
	LogicAnd Logic = "and"
	LogicOr  Logic = "or"
)

...

func ToLogic

func ToLogic(s string) Logic

ToLogic ...

func (Logic) String

func (t Logic) String() string

String ...

type Operation

type Operation interface {
	Name() string                                                   // 操作描述
	Expect(value interface{}) (interface{}, error)                  // 操作预期值
	Assert(ctx *Context, variable Variable, value interface{}) bool // 操作断言
}

Operation 操作接口

func NewOperation

func NewOperation(operationName string) (Operation, error)

NewOperation ...

type OperationBetween

type OperationBetween struct{}

OperationBetween ...

func (*OperationBetween) Assert

func (t *OperationBetween) Assert(ctx *Context, variable Variable, expect interface{}) bool

Assert ...

func (*OperationBetween) Expect

func (t *OperationBetween) Expect(value interface{}) (interface{}, error)

Expect ...

func (*OperationBetween) Name

func (t *OperationBetween) Name() string

Name ...

type OperationEqual

type OperationEqual struct{}

OperationEqual ...

func (*OperationEqual) Assert

func (t *OperationEqual) Assert(ctx *Context, variable Variable, expect interface{}) bool

Assert ...

func (*OperationEqual) Expect

func (t *OperationEqual) Expect(value interface{}) (interface{}, error)

Expect ...

func (*OperationEqual) Name

func (t *OperationEqual) Name() string

Name ...

type OperationEqualGT

type OperationEqualGT struct {
	OperationEqual
}

OperationEqualGT ...

func (*OperationEqualGT) Assert

func (t *OperationEqualGT) Assert(ctx *Context, variable Variable, expect interface{}) bool

Assert ...

func (*OperationEqualGT) Name

func (t *OperationEqualGT) Name() string

Name ...

type OperationEqualGTE

type OperationEqualGTE struct {
	OperationEqual
}

OperationEqualGTE ...

func (*OperationEqualGTE) Assert

func (t *OperationEqualGTE) Assert(ctx *Context, variable Variable, expect interface{}) bool

Assert ...

func (*OperationEqualGTE) Name

func (t *OperationEqualGTE) Name() string

Name ...

type OperationEqualLT

type OperationEqualLT struct {
	OperationEqual
}

OperationEqualLT ...

func (*OperationEqualLT) Assert

func (t *OperationEqualLT) Assert(ctx *Context, variable Variable, expect interface{}) bool

Assert ...

func (*OperationEqualLT) Name

func (t *OperationEqualLT) Name() string

Name ...

type OperationEqualLTE

type OperationEqualLTE struct {
	OperationEqual
}

OperationEqualLTE ...

func (*OperationEqualLTE) Assert

func (t *OperationEqualLTE) Assert(ctx *Context, variable Variable, expect interface{}) bool

Assert ...

func (*OperationEqualLTE) Name

func (t *OperationEqualLTE) Name() string

Name ...

type OperationEqualNot

type OperationEqualNot struct {
	OperationEqual
}

OperationEqualNot ...

func (*OperationEqualNot) Assert

func (t *OperationEqualNot) Assert(ctx *Context, variable Variable, expect interface{}) bool

Assert ...

func (*OperationEqualNot) Name

func (t *OperationEqualNot) Name() string

Name ...

type OperationFactory

type OperationFactory struct {
	// contains filtered or unexported fields
}

OperationFactory 操作实例工厂

func (*OperationFactory) Discovery

func (t *OperationFactory) Discovery(name string) Operation

Discovery 发现操作实例

func (*OperationFactory) Register

func (t *OperationFactory) Register(operation Operation)

Register 注册操作实例

type OperationHas

type OperationHas struct{}

OperationHas ...

func (*OperationHas) Assert

func (t *OperationHas) Assert(ctx *Context, variable Variable, expect interface{}) bool

Assert ...

func (*OperationHas) Expect

func (t *OperationHas) Expect(value interface{}) (interface{}, error)

Expect ...

func (*OperationHas) Name

func (t *OperationHas) Name() string

Name ...

type OperationIn

type OperationIn struct{}

OperationIn ...

func (*OperationIn) Assert

func (t *OperationIn) Assert(ctx *Context, variable Variable, expect interface{}) bool

Assert ...

func (*OperationIn) Expect

func (t *OperationIn) Expect(value interface{}) (interface{}, error)

Expect ...

func (*OperationIn) Name

func (t *OperationIn) Name() string

Name ...

type OperationMatch

type OperationMatch struct{}

OperationMatch ...

func (*OperationMatch) Assert

func (t *OperationMatch) Assert(ctx *Context, variable Variable, expect interface{}) bool

Assert ...

func (*OperationMatch) Expect

func (t *OperationMatch) Expect(value interface{}) (interface{}, error)

Expect ...

func (*OperationMatch) Name

func (t *OperationMatch) Name() string

Name ...

type OperationNotIn

type OperationNotIn struct {
	OperationIn
}

OperationNotIn ...

func (*OperationNotIn) Assert

func (t *OperationNotIn) Assert(ctx *Context, variable Variable, expect interface{}) bool

Assert ...

func (*OperationNotIn) Name

func (t *OperationNotIn) Name() string

Name ...

type OperationNotMatch

type OperationNotMatch struct {
	OperationMatch
}

OperationNotMatch ...

func (*OperationNotMatch) Assert

func (t *OperationNotMatch) Assert(ctx *Context, variable Variable, expect interface{}) bool

Assert ...

func (*OperationNotMatch) Name

func (t *OperationNotMatch) Name() string

Name ...

type Variable

type Variable interface {
	Name() string               // 变量名称
	Value(*Context) interface{} // 变量值
}

Variable 变量接口

func NewVariable

func NewVariable(name string) (Variable, error)

NewVariable ...

type VariableCreator

type VariableCreator = func(string) Variable

VariableCreator 变量生成器

type VariableCtx

type VariableCtx struct {
	// contains filtered or unexported fields
}

VariableCtx ...

func (*VariableCtx) Name

func (t *VariableCtx) Name() string

Name ...

func (*VariableCtx) Value

func (t *VariableCtx) Value(ctx *Context) interface{}

Value ...

type VariableFactory

type VariableFactory struct {
	// contains filtered or unexported fields
}

VariableFactory 变量实例工厂

func (*VariableFactory) Discovery

func (t *VariableFactory) Discovery(name string) Variable

Discovery 发现变量实例

func (*VariableFactory) Register

func (t *VariableFactory) Register(name string, creator VariableCreator)

Register 注册变量实例

type VariableTime

type VariableTime struct {
	// contains filtered or unexported fields
}

VariableTime ...

func (*VariableTime) Name

func (t *VariableTime) Name() string

Name ...

func (*VariableTime) Value

func (t *VariableTime) Value(ctx *Context) interface{}

Value ...

Jump to

Keyboard shortcuts

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