core

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2021 License: MIT Imports: 22 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Cacheable   = true
	Uncacheable = false
)

Functions

func CacheID

func CacheID(v string) uint64

func Clone

func Clone(v interface{}) interface{}

func GetVariableValue

func GetVariableValue(ctx *Context, v Variable) interface{}

GetVariableValue get value of variable, also handlers variable cacheing, hooking logic

func HashID

func HashID(v string) uint64

func IsArray

func IsArray(v interface{}) bool

func IsScalar

func IsScalar(v interface{}) bool

func ToArray

func ToArray(value interface{}) []interface{}

ToArray convert value to []interface{}

Types

type AnyOperation

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

----------------------------------------------------------------------------------

func (*AnyOperation) PrepareValue

func (o *AnyOperation) PrepareValue(value interface{}) (interface{}, error)

func (*AnyOperation) Run

func (o *AnyOperation) Run(ctx *Context, variable Variable, value interface{}) bool

func (AnyOperation) String

func (s AnyOperation) String() string

type Assignment

type Assignment interface {
	Run(ctx *Context, data interface{}, key string, val interface{})
	PrepareValue(value interface{}) (interface{}, error)
}

type AssignmentFactory

type AssignmentFactory interface {
	Get(string) Assignment
	Register(Assignment, ...string)
}

func GetAssignmentFactory

func GetAssignmentFactory() AssignmentFactory

GetAssignmentFactory return AssignmentFactory for registering new Assigment

type BaseAssignmentPrepareValue

type BaseAssignmentPrepareValue struct{}

func (*BaseAssignmentPrepareValue) PrepareValue

func (self *BaseAssignmentPrepareValue) PrepareValue(value interface{}) (interface{}, error)

type BetweenOperation

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

----------------------------------------------------------------------------------

func (*BetweenOperation) PrepareValue

func (o *BetweenOperation) PrepareValue(value interface{}) (interface{}, error)

func (*BetweenOperation) Run

func (o *BetweenOperation) Run(ctx *Context, variable Variable, value interface{}) bool

func (BetweenOperation) String

func (s BetweenOperation) String() string

type Cache

type Cache interface {
	Load(key interface{}) (interface{}, bool)
	Store(key, value interface{})
	Delete(key interface{})
}

func NewCache

func NewCache() Cache

type Condition

type Condition interface {
	Success(ctx *Context) bool
	String() string
}

Condition interface

func NewCondition

func NewCondition(item []interface{}, groupLogic GROUP_LOGIC) (Condition, error)

type ConditionGroup

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

func NewConditionGroup

func NewConditionGroup(logic GROUP_LOGIC) *ConditionGroup

func (*ConditionGroup) String

func (c *ConditionGroup) String() string

func (*ConditionGroup) Success

func (c *ConditionGroup) Success(ctx *Context) bool

type Context

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

func NewContext

func NewContext() *Context

func WithContext

func WithContext(ctx context.Context, opts ...ContextOption) *Context

func WithData

func WithData(ctx context.Context, data interface{}) *Context

WithData return new *Context contains data. call every time the filter runs, to make data thread-safe

func (*Context) Cache

func (c *Context) Cache() Cache

Cache return filter Cache object

func (*Context) Data

func (c *Context) Data() interface{}

Data return filter data

func (*Context) Deadline

func (c *Context) Deadline() (deadline time.Time, ok bool)

Implements context.Context interface

func (*Context) Delete

func (c *Context) Delete(key string)

Delete delte context data

func (*Context) Done

func (c *Context) Done() <-chan struct{}

func (*Context) Err

func (c *Context) Err() error

func (*Context) Get

func (c *Context) Get(key string) (value interface{}, exists bool)

Get get context data

func (*Context) GetAll

func (c *Context) GetAll() map[string]interface{}

GetAll return a map contains all context data

func (*Context) Set

func (c *Context) Set(key string, value interface{})

Set set context data

func (*Context) Trace

func (c *Context) Trace() Trace

Trace return Trace

func (*Context) Value

func (c *Context) Value(key interface{}) interface{}

type ContextOption

type ContextOption interface {
	// contains filtered or unexported methods
}

func WithCache

func WithCache(cache Cache) ContextOption

WithCache ContextOption

func WithTrace

func WithTrace(trace Trace) ContextOption

WithTrace ContextOption

type ContextOptionFunc

type ContextOptionFunc func(*Context)

type DeleteAssignment

type DeleteAssignment struct{}

func (*DeleteAssignment) PrepareValue

func (self *DeleteAssignment) PrepareValue(value interface{}) (interface{}, error)

func (*DeleteAssignment) Run

func (self *DeleteAssignment) Run(_ *Context, data interface{}, key string, value interface{})

type Deleter

type Deleter interface {
	AssignmentDelete(key string, value interface{}) bool
}

["key", "-", ["key"]]

type EqualAssignment

type EqualAssignment struct{ BaseAssignmentPrepareValue }

func (*EqualAssignment) Run

func (self *EqualAssignment) Run(_ *Context, data interface{}, key string, value interface{})

type EqualOperation

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

----------------------------------------------------------------------------------

func (EqualOperation) PrepareValue

func (o EqualOperation) PrepareValue(value interface{}) (interface{}, error)

func (*EqualOperation) Run

func (o *EqualOperation) Run(ctx *Context, variable Variable, value interface{}) bool

func (EqualOperation) String

func (s EqualOperation) String() string

type Executor

type Executor interface {
	Execute(*Context, interface{})
}

Executor

func NewExecutor

func NewExecutor(item []interface{}) (Executor, error)

type ExecutorGroup

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

ExecutorGroup

func NewExecutorGroup

func NewExecutorGroup() *ExecutorGroup

func (*ExecutorGroup) Execute

func (e *ExecutorGroup) Execute(ctx *Context, data interface{})

type GROUP_LOGIC

type GROUP_LOGIC int

ConditionGroup

const (
	LOGIC_ALL GROUP_LOGIC = iota
	LOGIC_ANY
	LOGIC_NONE
	LOGIC_ANY_NOT
)

type GeOperation

type GeOperation struct {
	LtOperation
	// contains filtered or unexported fields
}

----------------------------------------------------------------------------------

func (GeOperation) PrepareValue

func (o GeOperation) PrepareValue(value interface{}) (interface{}, error)

func (*GeOperation) Run

func (o *GeOperation) Run(ctx *Context, variable Variable, value interface{}) bool

func (GeOperation) String

func (s GeOperation) String() string

type GroupAssign

type GroupAssign struct{}

func (*GroupAssign) PrepareValue

func (a *GroupAssign) PrepareValue(value interface{}) (val interface{}, err error)

func (*GroupAssign) Run

func (a *GroupAssign) Run(ctx *Context, data interface{}, key string, value interface{})

type GtOperation

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

----------------------------------------------------------------------------------

func (GtOperation) PrepareValue

func (o GtOperation) PrepareValue(value interface{}) (interface{}, error)

func (*GtOperation) Run

func (o *GtOperation) Run(ctx *Context, variable Variable, value interface{}) bool

func (GtOperation) String

func (s GtOperation) String() string

type HasOperation

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

----------------------------------------------------------------------------------

func (*HasOperation) PrepareValue

func (o *HasOperation) PrepareValue(value interface{}) (interface{}, error)

func (*HasOperation) Run

func (o *HasOperation) Run(ctx *Context, variable Variable, value interface{}) bool

func (HasOperation) String

func (s HasOperation) String() string

type InOperation

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

----------------------------------------------------------------------------------

func (*InOperation) PrepareValue

func (o *InOperation) PrepareValue(value interface{}) (interface{}, error)

func (*InOperation) Run

func (o *InOperation) Run(ctx *Context, variable Variable, value interface{}) bool

func (InOperation) String

func (s InOperation) String() string

type LeOperation

type LeOperation struct {
	GtOperation
	// contains filtered or unexported fields
}

----------------------------------------------------------------------------------

func (LeOperation) PrepareValue

func (o LeOperation) PrepareValue(value interface{}) (interface{}, error)

func (*LeOperation) Run

func (o *LeOperation) Run(ctx *Context, variable Variable, value interface{}) bool

func (LeOperation) String

func (s LeOperation) String() string

type LtOperation

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

----------------------------------------------------------------------------------

func (LtOperation) PrepareValue

func (o LtOperation) PrepareValue(value interface{}) (interface{}, error)

func (*LtOperation) Run

func (o *LtOperation) Run(ctx *Context, variable Variable, value interface{}) bool

func (LtOperation) String

func (s LtOperation) String() string

type MatchOperation

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

----------------------------------------------------------------------------------

func (*MatchOperation) PrepareValue

func (o *MatchOperation) PrepareValue(value interface{}) (interface{}, error)

func (*MatchOperation) Run

func (o *MatchOperation) Run(ctx *Context, variable Variable, value interface{}) bool

func (MatchOperation) String

func (s MatchOperation) String() string

type MergeAssignment

type MergeAssignment struct{}

func (*MergeAssignment) PrepareValue

func (self *MergeAssignment) PrepareValue(value interface{}) (interface{}, error)

func (*MergeAssignment) Run

func (self *MergeAssignment) Run(_ *Context, data interface{}, key string, value interface{})

type Merger

type Merger interface {
	AssignmentMerge(key string, value interface{}) bool
}

["key", "+", {}]

type NoneOperation

type NoneOperation struct {
	AnyOperation
	// contains filtered or unexported fields
}

----------------------------------------------------------------------------------

func (*NoneOperation) Run

func (o *NoneOperation) Run(ctx *Context, variable Variable, value interface{}) bool

func (NoneOperation) String

func (s NoneOperation) String() string

type NotEqualOperation

type NotEqualOperation struct {
	EqualOperation
	// contains filtered or unexported fields
}

----------------------------------------------------------------------------------

func (NotEqualOperation) PrepareValue

func (o NotEqualOperation) PrepareValue(value interface{}) (interface{}, error)

func (*NotEqualOperation) Run

func (o *NotEqualOperation) Run(ctx *Context, variable Variable, value interface{}) bool

func (NotEqualOperation) String

func (s NotEqualOperation) String() string

type NotInOperation

type NotInOperation struct {
	InOperation
	// contains filtered or unexported fields
}

----------------------------------------------------------------------------------

func (*NotInOperation) Run

func (o *NotInOperation) Run(ctx *Context, variable Variable, value interface{}) bool

func (NotInOperation) String

func (s NotInOperation) String() string

type NotMatchOperation

type NotMatchOperation struct {
	MatchOperation
	// contains filtered or unexported fields
}

----------------------------------------------------------------------------------

func (*NotMatchOperation) Run

func (o *NotMatchOperation) Run(ctx *Context, variable Variable, value interface{}) bool

func (NotMatchOperation) String

func (s NotMatchOperation) String() string

type Operation

type Operation interface {
	Run(ctx *Context, variable Variable, value interface{}) bool
	PrepareValue(value interface{}) (interface{}, error)
	String() string
}

type OperationFactory

type OperationFactory interface {
	Get(string) Operation
	Register(Operation, ...string)
}

func GetOperationFactory

func GetOperationFactory() OperationFactory

type ProbabilitySet

type ProbabilitySet struct {
}

ProbabilitySet set value with specified probability. e.g. :

["key", "*=", [ [10, "value1"], [10, "value2"], [10, "value3"] ]]
value1,value2,value3 has the same weight 10, each of them has a probability 10/(10+10+10) = 1/3 to been chosen.

func (*ProbabilitySet) PrepareValue

func (a *ProbabilitySet) PrepareValue(value interface{}) (val interface{}, err error)

func (*ProbabilitySet) Run

func (a *ProbabilitySet) Run(ctx *Context, data interface{}, key string, value interface{})

type Setter

type Setter interface {
	AssignmentSet(key string, value interface{}) bool
}

["key", "=", "val"]

type SimpleVariable

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

SimpleVariable implements Variable interface

func (*SimpleVariable) Cacheable

func (v *SimpleVariable) Cacheable() bool

func (*SimpleVariable) Name

func (v *SimpleVariable) Name() string

func (*SimpleVariable) Value

func (v *SimpleVariable) Value(ctx *Context) interface{}

type StaticValue

type StaticValue struct {
	Val interface{}
}

StaticValue static value implements Valuer interface

func (StaticValue) Value

func (v StaticValue) Value(_ *Context) interface{}

type StdCondition

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

StdCondition

func (*StdCondition) String

func (c *StdCondition) String() string

func (*StdCondition) Success

func (c *StdCondition) Success(ctx *Context) bool

type StdExecutor

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

StdExecutor

func (*StdExecutor) Execute

func (e *StdExecutor) Execute(ctx *Context, data interface{})

type StdLogger

type StdLogger interface {
	Print(v ...interface{})
	Printf(format string, v ...interface{})
	Println(v ...interface{})
}
var (
	Logger StdLogger = log.New(ioutil.Discard, "[filter]", log.LstdFlags)
)

type Trace

type Trace interface {
	Enter(name string) Trace
	Leave(name string) Trace
	Log(a ...interface{}) Trace
}

func NewTrace

func NewTrace(w io.Writer) Trace

type ValueFunc

type ValueFunc func(*Context) interface{}

ValueFunc implements Valuer interface

func (ValueFunc) Value

func (f ValueFunc) Value(ctx *Context) interface{}

type Valuer

type Valuer interface {
	Value(*Context) interface{}
}

type Variable

type Variable interface {
	Cacheable() bool
	Name() string
	Valuer
}

func NewSimpleVariable

func NewSimpleVariable(name string, cacheable bool, value Valuer) Variable

type VariableCreator

type VariableCreator interface {
	Create(string) Variable
}

type VariableCreatorFunc

type VariableCreatorFunc func(string) Variable

func SingletonVariableCreator

func SingletonVariableCreator(instance Variable) VariableCreatorFunc

func (VariableCreatorFunc) Create

func (f VariableCreatorFunc) Create(name string) Variable

type VariableFactory

type VariableFactory interface {
	VariableCreator
	Register(VariableCreator, ...string)
	// RegisterAlias register aliases for destination variable
	// RegisterAlias("time", "t") t => t
	// RegisterAlias("ctx.something", "s") s.l => ctx.something.l
	RegisterAlias(dest string, aliases ...string) error
}

func GetVariableFactory

func GetVariableFactory() VariableFactory

GetVariableFactory return VariableFactory

Jump to

Keyboard shortcuts

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