Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alecthomas/expr
Runtime evaluation of Go-like expressions
https://github.com/alecthomas/expr
Last synced: 16 days ago
JSON representation
Runtime evaluation of Go-like expressions
- Host: GitHub
- URL: https://github.com/alecthomas/expr
- Owner: alecthomas
- Created: 2014-08-26T23:28:15.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2023-12-02T17:47:41.000Z (12 months ago)
- Last Synced: 2024-10-10T16:07:06.188Z (about 1 month ago)
- Language: Go
- Size: 4.88 KB
- Stars: 4
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Runtime evaluation of Go-like expressions
# What?
eg.
```go
e := expr.MustCompile("a + 1 > 2")
e.Bool(expr.V{"a": 0}) == false
e.Bool(expr.V{"a": 1}) == false
e.Bool(expr.V{"a": 2}) == true
```and
```go
e = expr.MustCompile("(a + 2) * 10")
n, err := e.Eval(expr.V{"a": 1})
n.(int64) == 30
```It *does not* support:
- Function calls (though this would be useful).
- Slices or arrays.It *does* support:
- Truthiness evaluation, ala Python: eg. given `V{"a": 1}`, evaluating `a` will be true.
- Automatic type coercion. eg. `"a" + 10` == `"a10"`
- Nested fields. eg. `A.B == 2`# Why?
If you want to add simple expression-based filtering or numeric evaluation,
this might fit your needs.# Where?
## Install
```sh
$ go get github.com/alecthomas/expr
```## Docs
You can find the API documentation on [godoc](http://godoc.org/github.com/alecthomas/expr).