expression

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: MIT, MIT Imports: 11 Imported by: 0

README

expression EL表达式

Install

go get github.com/heartlhj/go-expression

功能

  • 字符串的提取和比较
    context := spel.StandardEvaluationContext{}
    m := make(map[string]interface{})
    m["name"] = "lisi"
    m["age"] = 18
    context.SetVariables(m)
    parser := SpelExpressionParser{}
    expressionString := "#name=='lisi'"
    //expressionString := "#name" //返回lisi
    valueContext := parser.ParseExpression(expressionString).GetValueContext(&context)
  • 数字比较,支持int和 float64
    context := spel.StandardEvaluationContext{}
    m := make(map[string]interface{})
    m["name"] = "lisi"
    m["age"] = 18
    context.SetVariables(m)
    parser := SpelExpressionParser{}
    expressionString := "#age>=10"
    valueContext := parser.ParseExpression(expressionString).GetValueContext(&context)

float64比较

    context := spel.StandardEvaluationContext{}
    m := make(map[string]interface{})
    var ageFloat float64
    ageFloat = 10
    m["num"] = ageFloat
    context.SetVariables(m)
    parser := SpelExpressionParser{}
    expressionString := "#num>=9f"
    valueContext := parser.ParseExpression(expressionString).GetValueContext(&context)
  • 与(&&)或 (||)操作
    context := spel.StandardEvaluationContext{}
    m := make(map[string]interface{})
    m["name"] = "lisi"
    m["age"] = 18
    context.SetVariables(m)
    parser := SpelExpressionParser{}
    expressionString := "#name=='lisi' && #age>=3"
    valueContext := parser.ParseExpression(expressionString).GetValueContext(&context)
  • 复合结构,迭代提取
    context := spel.StandardEvaluationContext{}
    context.AddPropertyAccessor(spel.MapAccessor{})
    m := make(map[string]interface{})
    m["name"] = "lisi"
    m["age"] = 18
    m1 := make(map[string]interface{})
    m2 := make(map[string]interface{})
    m2["num"] = 12
    m1["code"] = m2
    m["order"] = m1
    context.SetVariables(m)
    parser := SpelExpressionParser{}
    expressionString := "#order.code.num==12"
    valueContext := parser.ParseExpression(expressionString).GetValueContext(&context)
  • 数组和切片提取
    context := spel.StandardEvaluationContext{}
    context.AddPropertyAccessor(spel.MapAccessor{})
    m := make(map[string]interface{})
    m["name"] = "lisi"
    m["age"] = 18
    m1 := make(map[string]interface{})
    //切片
    //orders := make([]Order, 2)
    //数组
    orders := [2]Order{}
    orders[0] = Order{name: "lisi", age: 12}
    orders[1] = Order{name: "wang", age: 24}
    m1["code"] = orders
    m["order"] = m1
    context.SetVariables(m)
    parser := SpelExpressionParser{}
    expressionString := "#order.code[0].name=='lisi'"
    valueContext := parser.ParseExpression(expressionString).GetValueContext(&context)
  • 字符串下标判断提取
    context := spel.StandardEvaluationContext{}
    context.AddPropertyAccessor(spel.MapAccessor{})
    m := make(map[string]interface{})
    m["name"] = "lisi"
    m["age"] = 18
    context.SetVariables(m)
    parser := SpelExpressionParser{}
    expressionString := "#name[2]=='i'"
    valueContext := parser.ParseExpression(expressionString).GetValueContext(&context)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bracket

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

type CompositeStringExpression

type CompositeStringExpression struct {
	ExpressionString string
	Expressions      []Expression
}

func (*CompositeStringExpression) GetExpressionString

func (c *CompositeStringExpression) GetExpressionString() string

func (*CompositeStringExpression) GetValue

func (c *CompositeStringExpression) GetValue() interface{}

func (*CompositeStringExpression) GetValueContext

func (c *CompositeStringExpression) GetValueContext(context spel.EvaluationContext) interface{}

type Expression

type Expression interface {
	GetExpressionString() string

	GetValue() interface{}

	GetValueContext(context spel.EvaluationContext) interface{}
}

获取值

type ExpressionParser

type ExpressionParser interface {
	ParseExpression(var1 string) Expression

	DoParseExpression(var1 string) Expression
}

type InternalSpelExpressionParser

type InternalSpelExpressionParser struct {
	*TemplateAwareExpressionParser

	Configuration SpelParserConfiguration
	// contains filtered or unexported fields
}

func (*InternalSpelExpressionParser) DoParseExpression

func (i *InternalSpelExpressionParser) DoParseExpression(expressionString string) Expression

type LiteralExpression

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

func (*LiteralExpression) GetExpressionString

func (l *LiteralExpression) GetExpressionString() string

func (*LiteralExpression) GetValue

func (l *LiteralExpression) GetValue() interface{}

func (*LiteralExpression) GetValueContext

func (l *LiteralExpression) GetValueContext(context spel.EvaluationContext) interface{}

type ParserContext

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

type SpelExpressionParser

type SpelExpressionParser struct {
	*TemplateAwareExpressionParser
}

type TemplateAwareExpressionParser

type TemplateAwareExpressionParser struct {
	Bracket
}

func (*TemplateAwareExpressionParser) DoParseExpression

func (s *TemplateAwareExpressionParser) DoParseExpression(expressionString string) Expression

func (*TemplateAwareExpressionParser) ParseExpression

func (t *TemplateAwareExpressionParser) ParseExpression(expressionString string) Expression

type TemplateParserContext

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

type Value

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

Directories

Path Synopsis
ast

Jump to

Keyboard shortcuts

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