jsonengine

package
v0.0.0-...-faf4214 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package jsonengine 提供基于 jsonvalue 的 JSON 规则引擎

Index

Constants

View Source
const (
	ErrNotFound          = jsonvalue.ErrNotFound
	ErrTypeNotMatch      = jsonvalue.ErrTypeNotMatch
	ErrImportTargetValue = jsonvalue.Error("import target value error")
	ErrIllegalOperator   = jsonvalue.Error("illegal operator")
)

Variables

This section is empty.

Functions

func Match

func Match(value any, cond Condition, opts ...Option) (bool, error)

Match 规则匹配

Types

type AND

type AND []Condition

AND 表示几个与条件

type Condition

type Condition struct {
	Expr

	OR  OR  `json:"or,omitempty"  yaml:"or,omitempty"`
	AND AND `json:"and,omitempty" yaml:"and,omitempty"`

	NOT *NOT `json:"not,omitempty" yaml:"not,omitempty"`
}

Condition 表示一个条件

func (*Condition) UnmarshalJSON

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

UnmarshalJSON is redefined to support simple SQL style expression written as a 3-element-array, like ["result.list.[+].code", "=", 200]

type Expr

type Expr struct {
	Field    string `json:"field,omitempty" yaml:"field,omitempty"`
	Operator string `json:"op"              yaml:"op"`
	Value    any    `json:"value"           yaml:"value"`
	// contains filtered or unexported fields
}

Expr 表示一个最简单的表达式条件。

Field 使用点分隔, 需要注意的是, [*] 表示数组中所有的类型都需要匹配, [+] 表示数组中任意一个满足条件即可

type NOT

type NOT struct {
	Condition
}

NOT 表示非

type OR

type OR []Condition

OR 表示几个或条件

type Option

type Option func(*options)

Option 表示可用参数

func OptDateTimeFormat

func OptDateTimeFormat(format string) Option

OptDateTimeFormat 表示时间格式, Go 格式, 用于当目标是 string 的时候, 检查是不是时间

func OptWhenNotFound

func OptWhenNotFound(typ ReturnType) Option

OptWhenNotFound 表示当查找不到值时, 如何返回

func OptWhenTypeMismatch

func OptWhenTypeMismatch(typ ReturnType) Option

OptWhenTypeMismatch 表示当值类型不匹配时, 如何返回

type ReturnType

type ReturnType uint

ReturnType 表示如何返回

const (
	// ReturnError 表示返回 jsonvalue 的错误
	ReturnError ReturnType = iota
	// ReturnFalse 表示返回不匹配
	ReturnFalse
)

Jump to

Keyboard shortcuts

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