Skip to content

Instantly share code, notes, and snippets.

@d4l3k
Last active July 6, 2016 02:14
Show Gist options
  • Save d4l3k/53ab3e333299ed9b93f0a1c1065a18b9 to your computer and use it in GitHub Desktop.
Save d4l3k/53ab3e333299ed9b93f0a1c1065a18b9 to your computer and use it in GitHub Desktop.
package main
import (
"log"
"github.com/Knetic/govaluate"
)
type parametersImpl struct {
get func(name string) (interface{}, error)
}
func (p *parametersImpl) Get(name string) (interface{}, error) {
return p.get(name)
}
func main() {
expression, err := govaluate.NewEvaluableExpression(`[count:"rack_.*"] < 3 || [replicas:\[first:"rack_.*"\]] < 3`)
if err != nil {
log.Fatal(err)
}
result, err := expression.Eval(&parametersImpl{
func(name string) (interface{}, error) {
log.Printf("parameter %q", name)
return 1, nil
},
})
if err != nil {
log.Fatal(err)
}
log.Printf("output %+v", result)
}
~/Developer/govaluate-test  go run main.go
2016/07/05 22:12:41 parameter "count:\"rack_.*\""
2016/07/05 22:12:41 parameter "replicas:[first:\"rack_.*\"]"
2016/07/05 22:12:41 output true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment