ruller

package
v0.0.0-...-b7a2e48 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 26, 2019 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(groupName string, ruleName string, rule Rule) error

Add adds a rule implementation to a group

func AddChild

func AddChild(groupName string, ruleName string, parentRuleName string, rule Rule) error

AddChild adds a rule implementation to a group

func AddRequiredInput

func AddRequiredInput(groupName string, inputName string, it InputType)

AddRequiredInput adds a input attribute name that is required before processing the rules

func Process

func Process(groupName string, input map[string]interface{}, options ProcessOptions) (map[string]interface{}, error)

Process process all rules in a group and return a resulting map with all values returned by the rules

func SetDefaultFlatten

func SetDefaultFlatten(groupName string, value bool)

SetDefaultFlatten sets whatever to flatten output or keep it hierarchical. This may be overriden during rules evaluation with a "_flatten" attribute in input

func SetDefaultKeepFirst

func SetDefaultKeepFirst(groupName string, value bool)

SetDefaultKeepFirst sets whatever to keep the first or the last occurence of an output attribute when flattening the output. This may be overriden during rules evaluation with a "_keepFirst" attribute in input

func SetRequestFilter

func SetRequestFilter(rf RequestFilter)

SetRequestFilter set the function that will be called at every call

func SetResponseFilter

func SetResponseFilter(rf ResponseFilter)

SetResponseFilter set the function that will be called at every call with output. If returns true, won't perform the default JSON renderization

func StartServer

func StartServer() error

StartServer Initialize and start REST server

Types

type Context

type Context struct {
	Input          map[string]interface{}
	ChildrenOutput map[string]interface{}
}

Context used as input for rule processing

type InputType

type InputType int

InputType input type for required input names declaration

const (
	//String input type
	String InputType = iota
	//Float64 input type
	Float64
	//Bool input type
	Bool
)

type ProcessOptions

type ProcessOptions struct {
	//MergeKeepFirst When merging output results from rules, if there is a duplicate key, keep the first or the last result found. applies when using flatten output. defaults to true
	MergeKeepFirst bool
	//AddRuleInfo Add rule info attributes (name etc) to the output tree when not flatten. defaults to false
	AddRuleInfo bool
	//Get all rules's results and merge all outputs into a single flat map. If false, the output will come the same way as the hierarchy of rules. Defaults to true
	FlattenOutput bool
}

ProcessOptions options for rule process

type RequestFilter

type RequestFilter func(r *http.Request, input map[string]interface{}) error

RequestFilter Function called on every HTTP call before rules processing. params: request, input attributes returns: error

type ResponseFilter

type ResponseFilter func(w http.ResponseWriter, input map[string]interface{}, output map[string]interface{}, outBytes []byte) (bool, error)

ResponseFilter Function called on every HTTP call after rules processing. params: http response writer, input attribute, output attributes. returns: bool true if ruller should interrupt renderization and rely on what the filter did, error

type Rule

type Rule func(Context) (map[string]interface{}, error)

Rule Function that defines a rule. The rule accepts a map as input and returns a map as output. The output map maybe nil

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL