5

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?

Dave C
  • 7,729
  • 4
  • 49
  • 65
rui
  • 81
  • 1
  • 1
  • 3

4 Answers4

3

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:

Samuel Lampa
  • 4,336
  • 5
  • 42
  • 63
  • Looking at the list over at godoc.org, godec (https://github.com/steveyen/gdec) seems to be potentially interesting , claiming to be "declarative golang data & rules processing". – Samuel Lampa May 08 '14 at 21:18
1

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.

Cera
  • 1,879
  • 2
  • 20
  • 29
  • It is not for testing purpose, we just need a temptable framework to handle boolean evaluation from a rule description file instead of hard code the logic in the code. – rui Jun 26 '13 at 22:16
1

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;
}
Ferdinand Neman
  • 680
  • 3
  • 6
0

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.

Also code really good: Build Status Go Report Card Code Coverage

Anton Medvedev
  • 3,393
  • 3
  • 28
  • 40