Documentation ¶
Overview ¶
Package roulette is used for firing business actions based on a textual decision tree. It uses the powerful control structures in text/template and parsing from encoding/xml to build the tree from an rules xml file.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Parser ¶
type Parser interface { Execute(vals interface{}) GetResult() Result }
Parser interface provides methods for the executor to update the tree, execute the values and get result.
func NewParser ¶
func NewParser(data []byte, config ...TextTemplateParserConfig) (Parser, error)
NewParser returns a TextTemplateParser with default config
func NewTextTemplateParser ¶
func NewTextTemplateParser(data []byte, config TextTemplateParserConfig) (Parser, error)
NewTextTemplateParser returns a new roulette format xml parser.
type QueueExecute ¶
type QueueExecute interface { Execute(in <-chan interface{}, out chan<- interface{}) // in channel to write, out channel to read. CloseResult() }
QueueExecute interface provides methods to retrieve a parser and a method which executes on the incoming values on the input channel.
func NewQueueExecutor ¶
func NewQueueExecutor(parser Parser) QueueExecute
NewQueueExecutor returns a new QueueExecutor
type QueueExecutor ¶
type QueueExecutor struct {
Parser Parser
}
QueueExecutor implements the QueueExecute
func (*QueueExecutor) CloseResult ¶
func (q *QueueExecutor) CloseResult()
CloseResult closes the result channel
func (*QueueExecutor) Execute ¶
func (q *QueueExecutor) Execute(in <-chan interface{}, out chan<- interface{})
Execute ...
type ResultCallback ¶
type ResultCallback struct {
// contains filtered or unexported fields
}
ResultCallback holds the out channel
func NewResultCallback ¶
func NewResultCallback(fn func(interface{})) *ResultCallback
NewResultCallback return a new ResultCallback
func (ResultCallback) Put ¶
func (q ResultCallback) Put(val interface{}, prevVal ...bool) bool
Put receives a value and put's it on the parser's out channel
type ResultQueue ¶
type ResultQueue struct {
// contains filtered or unexported fields
}
ResultQueue holds the out channel
func (ResultQueue) Put ¶
func (q ResultQueue) Put(val interface{}, prevVal ...bool) bool
Put receives a value and put's it on the parser's out channel
type Rule ¶
type Rule struct { Name string `xml:"name,attr"` Priority int `xml:"priority,attr"` Expr string `xml:",innerxml"` // contains filtered or unexported fields }
Rule is a single rule expression. A rule expression is a valid go text/template
type SimpleExecute ¶
type SimpleExecute interface {
Execute(vals ...interface{})
}
SimpleExecute interface provides methods to retrieve a parser and a method which executes on the incoming values.
func NewSimpleExecutor ¶
func NewSimpleExecutor(parser Parser) SimpleExecute
NewSimpleExecutor returns a new SimpleExecutor
type SimpleExecutor ¶
type SimpleExecutor struct {
Parser Parser
}
SimpleExecutor implements the SimpleExecute interface
func (*SimpleExecutor) Execute ¶
func (s *SimpleExecutor) Execute(vals ...interface{})
Execute executes rules in order of priority. one(true): executes in order of priority until a high priority rule is successful, after which execution stops
type TextTemplateParser ¶
type TextTemplateParser struct {
// contains filtered or unexported fields
}
TextTemplateParser holds the rules from a rule file
func (TextTemplateParser) Execute ¶
func (p TextTemplateParser) Execute(vals interface{})
Execute executes the parser's rulesets
func (TextTemplateParser) GetResult ¶
func (p TextTemplateParser) GetResult() Result
GetResult returns the parser's result.
type TextTemplateParserConfig ¶
type TextTemplateParserConfig struct { Userfuncs template.FuncMap DelimLeft string DelimRight string WorkflowPattern string // filter rulesets based on the pattern Result Result IsWildcardWorkflowPattern bool LogLevel string //info, debug, warn, error, fatal. default is info LogPath string //stdout, /path/to/file . default is stdout }
TextTemplateParserConfig sets the optional config for the TextTemplateParser
type TextTemplateRuleset ¶
type TextTemplateRuleset struct { Name string `xml:"name,attr"` FilterTypes string `xml:"filterTypes,attr"` FilterStrict bool `xml:"filterStrict,attr"` DataKey string `xml:"dataKey,attr"` ResultKey string `xml:"resultKey,attr"` Rules []Rule `xml:"rule"` PrioritiesCount string `xml:"prioritiesCount,attr"` Workflow string `xml:"workflow,attr"` // contains filtered or unexported fields }
TextTemplateRuleset is a collection of rules for a valid go type
func (TextTemplateRuleset) Execute ¶
func (t TextTemplateRuleset) Execute(vals interface{}) error
Execute ...
func (TextTemplateRuleset) Less ¶
func (t TextTemplateRuleset) Less(i, j int) bool
func (TextTemplateRuleset) Swap ¶
func (t TextTemplateRuleset) Swap(i, j int)
type XMLData ¶
type XMLData struct { Name xml.Name `xml:"roulette"` Rulesets []TextTemplateRuleset `xml:"ruleset"` }
XMLData contains the parsed roulette xml tree
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package log is a custom wrapper over logger so that a global configuration can be set and used across all the packages Use this instead of the standard library "log" package.
|
Package log is a custom wrapper over logger so that a global configuration can be set and used across all the packages Use this instead of the standard library "log" package. |