Skip to content
This repository has been archived by the owner on Jul 27, 2021. It is now read-only.

Latest commit

 

History

History
73 lines (61 loc) · 1.46 KB

README.md

File metadata and controls

73 lines (61 loc) · 1.46 KB

fished

Migrated to https://github.coupang.net/coupang/couplay-fished

Fish answers from rules and facts

Install

$ go get -u github.com/jonathansudibya/fished

or using dep

$ dep ensure -add github.com/jonathansudibya/fished

Structs

Rule :

type Rule struct {
	Output 			string   `json:"output"`
	Input  			[]string `json:"input"`
	Expression   	string   `json:"expression"`
	...
}

Engine:

type Engine struct {
    Facts         map[string]interface{}
	Rules         []Rule
	RuleFunctions map[string]govaluate.ExpressionFunction
	Jobs          chan int
    ...
}

Example

Please see in test file especially TestRun() function.

package main

import "github.com/jonathansudibya/fished"

func main() {
	e := fished.New(nil)
	e.SetRules([]Rule{
		Rule{
			Input: []string{"hello"},
			Output: "result_end",
			Expression: "hello == 'world'",
		}
	})
	e.SetFacts = map[string]interface{}{
		"hello": "world"
	}
	res, errs := e.Run()

	fmt.Println(res) // will result true
}

Notes

Remember it is more expensive to set new rules than to set facts.

Credits

This project is powered by

LICENSE

See LICENSE.md