https://github.com/sandertv/go-formula
A go package for simple formula parsing and evaluation
https://github.com/sandertv/go-formula
evaluate formula golang
Last synced: 4 days ago
JSON representation
A go package for simple formula parsing and evaluation
- Host: GitHub
- URL: https://github.com/sandertv/go-formula
- Owner: Sandertv
- License: mit
- Created: 2019-03-09T10:54:34.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-09-02T09:55:59.000Z (over 4 years ago)
- Last Synced: 2025-03-30T08:32:11.216Z (about 1 month ago)
- Topics: evaluate, formula, golang
- Language: Go
- Size: 45.9 KB
- Stars: 18
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-formula [](https://godoc.org/github.com/Sandertv/go-formula/v2)
A simple and fast formula parser and evaluator.## Getting Started
### Usage
Formulas may be parsed using the formula.New() function. The function returns a formula that may be evaluated
an unlimited amount of times. Note that parsing formulas is generally heavier than evaluating them, so it is
recommended to parse once and evaluate the same formula multiple times where applicable.```go
package mainimport (
"github.com/sandertv/go-formula/v2"
"log"
)func main() {
f, err := formula.New("17*x + pow(z*3, 3)")
if err != nil {
log.Print(err)
return
}
x := formula.Var("x", 4.5)
z := formula.Var("z", 5)
log.Printf("Formula output: %v", f.MustEval(x, z))
}
```### Documentation
https://godoc.org/github.com/Sandertv/go-formula/v2