Expression language and expression evaluation for Go
Expr
**Expr** is a Go-centric expression language designed to deliver dynamic configurations with unparalleled accuracy, safety, and speed.
**Expr** combines simple [syntax](https://expr-lang.org/docs/language-definition) with powerful features for ease of use:
javascript
// Allow only admins and moderators to moderate comments.
user.Groupin ["admin", "moderator"] || user.Id == comment.UserId
javascript
// Determine whether the request is in the permitted time window.
request.Time - resource.Age < duration("24h")
javascript
// Ensure all tweets are less than 240 characters.all(tweets, len(.Content) <= 240)
Features
Expr is a safe, fast, and intuitive expression evaluator optimized for the Go language.
Here are its standout features:
Safety and Isolation
Memory-Safe: Expr is designed with a focus on safety, ensuring that programs do not access unrelated memory or introduce memory vulnerabilities.
Side-Effect-Free: Expressions evaluated in Expr only compute outputs from their inputs, ensuring no side-effects that can change state or produce unintended results.
Always Terminating: Expr is designed to prevent infinite loops, ensuring that every program will conclude in a reasonable amount of time.
Go Integration
Seamless with Go: Integrate Expr into your Go projects without the need to redefine types.
Static Typing
Ensures type correctness and prevents runtime type errors.
Provides user-friendly error messages to assist with debugging and development.
Flexibility and Utility
Rich Operators: Offers a reasonable set of basic operators for a variety of applications.
Built-in Functions: Functions like all, none, any, one, filter, and map are provided out-of-the-box.
Performance
Optimized for Speed: Expr stands out in its performance, utilizing an optimizing compiler and a bytecode virtual machine. Check out these benchmarks for more details.