exp_calc

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

README

ExpCalc

表达式计算器

License GoDoc Go Report Card

特性

  • 参考 xorm、go-playground/validator.v8 等框架,用于实现复杂、灵活的逻辑判断,可用于业务中复杂的条件判断。如广告定向条件、流量分层策略等

安装

go get github.com/ant-libs-go/exp_calc

快速开始

// 注册操作符
Register("in", func(p interface{}, entry *entry) (bool, error) {
	// 解析p中的参数,与entry中的args进行对比判断
	code ...
})

// 创建calc实例
calc := New("appid:in:[1001] & (age:in:{"range": [10,30]} | sex:in:[1,2])")

// 定义参数
p := &struct {
	user int32
	Age  int32
	sex  int32
}{3, 20, 2}

fmt.Println(o.Calculate(p))

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(name string, fn func(p interface{}, entry *Entry) (bool, error))

Types

type Calc

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

func New

func New(exp string) *Calc

exp, format see function "exp2Entry":

appid:eq:[]

func (*Calc) Calculate

func (this *Calc) Calculate(p interface{}) (r bool, err error)

type Entry

type Entry struct {
	Name     string
	Args     interface{}
	Operator string
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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