We want to implement our business logic using Go, but we cannot find any good implementation of rules engine/inference engine for Go. Does anyone have any experience or suggestions?
The best example of something like this to my knowledge is the 'table-driven' approach to unit tests taken in much of the standard library. For example, the fmttests.
Beyond that, Go is a powerful, expressive language. What do you actually need? There are a number of examples of state machine implementations in Go, and a number of web frameworks with declarative JSON configuration.
If you mean proper logic programming, there's no popular Go library for it yet.
There is a project that aims to implement an ISO Prolog compiler in Go:
I haven't tested it, but given that it implements some basic Prolog, that should be quite a capable rule-based reasoning engine, AFAIS.
Otherwise, a search for "rule" over at godoc.org also yields a bunch of packages:
Take a look at https://github.com/antonmedv/expr
It can parse next expressions:
# Get the special price if
user.Group in ["good_customers", "collaborator"]
# Promote article to the homepage when
len(article.Comments) > 100 and article.Category not in ["misc"]
# Send an alert when
product.Stock < 15
Type check them and evaluate.
If you're familiar with JBoss Drools, now there's something similar in Golang. Check this out https://github.com/newm4n/grool
It has DSL similar to Drools DRL, called GRL.
rule SlowDown "When testcar is slowing down we keep decreasing the speed." salience 10 {
when
TestCar.SpeedUp == false && TestCar.Speed > 0
then
TestCar.Speed = TestCar.Speed - TestCar.SpeedIncrement;
DistanceRecord.TotalDistance = DistanceRecord.TotalDistance + TestCar.Speed;
}