Last active
July 6, 2016 02:14
-
-
Save d4l3k/53ab3e333299ed9b93f0a1c1065a18b9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(¶metersImpl{ | |
func(name string) (interface{}, error) { | |
log.Printf("parameter %q", name) | |
return 1, nil | |
}, | |
}) | |
if err != nil { | |
log.Fatal(err) | |
} | |
log.Printf("output %+v", result) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~/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