Documentation
¶
Index ¶
- Variables
- func GetNodePathFromContext(ctx context.Context) []string
- type Operator
- type Tree
- func (t *Tree) AddNode(node *Tree)
- func (t *Tree) Context() context.Context
- func (t *Tree) GetChild() []*Tree
- func (t *Tree) GetParent() *Tree
- func (t *Tree) Next(jsonRequest map[string]interface{}, config *TreeOptions) (*Tree, error)
- func (t *Tree) Resolve(request map[string]interface{}, options ...func(t *TreeOptions)) (*Tree, error)
- func (t *Tree) ResolveJSON(jsonRequest []byte, options ...func(t *TreeOptions)) (*Tree, error)
- func (t *Tree) ResolveJSONWithContext(ctx context.Context, jsonRequest []byte, options ...func(t *TreeOptions)) (*Tree, context.Context, error)
- func (t *Tree) ResolveWithContext(ctx context.Context, request map[string]interface{}, ...) (*Tree, context.Context, error)
- func (t *Tree) String() string
- func (t *Tree) ValueToDraw() string
- func (t *Tree) WithContext(ctx context.Context) *Tree
- type TreeOptions
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrBadType = errors.New("types are different")
ErrBadType : Types between request and Tree are different, so we are unable to compare them
var ErrNoNode = errors.New("Node is nil")
ErrNoNode : No Node was sent
var ErrNoParentNode = errors.New("Node has no parent")
ErrNoParentNode : Node has no parent
var ErrNotSupportedType = errors.New("type not supported")
ErrNotSupportedType : Type in request are not supported
var ErrOperator = errors.New("unknow operator")
ErrOperator : unknow operator
var FallbackType = "fallback"
FallbackType the fallback value (by default = "fallback"), can be overrided
Functions ¶
func GetNodePathFromContext ¶
GetNodePathFromContext gets the node path from the context
Types ¶
type Tree ¶
type Tree struct { ID int `json:"id"` Name string `json:"name"` ParentID int `json:"parent_id"` Value interface{} `json:"value"` Operator string `json:"operator"` Key string `json:"key"` Order int `json:"order"` Content interface{} `json:"content"` Headers map[string]interface{} `json:"headers"` // contains filtered or unexported fields }
Tree represents a Tree
func LoadTree ¶
LoadTree gets a json on build the Tree related
Example ¶
jsonTree := []byte(`[ { "id": 1, "name": "root" }, { "id": 2, "parent_id": 1, "key": "sayHello", "operator": "eq", "value": true }, { "id": 3, "parent_id": 1, "key": "sayHello", "operator": "eq", "value": false }, { "id": 4, "parent_id": 3, "Name": "Goodbye" }, { "id": 5, "parent_id": 2, "key": "gender", "operator": "eq", "value": "F" }, { "id": 6, "parent_id": 5, "Name": "Hello Miss" }, { "id": 7, "parent_id": 2, "value": "fallback" }, { "id": 8, "parent_id": 7, "Name": "Hello" }, { "id": 9, "parent_id": 2, "key": "gender", "operator": "eq", "value": "M" }, { "id": 10, "parent_id": 9, "key": "age", "operator": "gt", "value": 60 }, { "id": 11, "parent_id": 10, "Name": "Hello Sir" }, { "id": 12, "parent_id": 9, "key": "age", "operator": "lte", "value": 60 }, { "id": 13, "parent_id": 12, "Name": "Hello dude" } ]`) t, err := LoadTree(jsonTree) if err != nil { fmt.Println(err) os.Exit(-1) } request := make(map[string]interface{}) request["sayHello"] = true request["gender"] = "M" request["age"] = 35.0 //does not use int, the engine only support float (if you want do a PR to include int, it's up to you) /*request := []byte(`{ "sayHello": false, "gender": "M", "age": 35 }`) v, _ := t.ResolveJSON(request) */ v, _ := t.Resolve(request) fmt.Println(v.Name) // output : Hello dude
Output:
func (*Tree) Next ¶
func (t *Tree) Next(jsonRequest map[string]interface{}, config *TreeOptions) (*Tree, error)
Next evaluate which will be the next Node according to the jsonRequest
func (*Tree) Resolve ¶
func (t *Tree) Resolve(request map[string]interface{}, options ...func(t *TreeOptions)) (*Tree, error)
Resolve calculate which will be the selected node according to the map request
func (*Tree) ResolveJSON ¶
func (t *Tree) ResolveJSON(jsonRequest []byte, options ...func(t *TreeOptions)) (*Tree, error)
ResolveJSON calculate which will be the selected node according to the jsonRequest
func (*Tree) ResolveJSONWithContext ¶ added in v0.3.1
func (t *Tree) ResolveJSONWithContext(ctx context.Context, jsonRequest []byte, options ...func(t *TreeOptions)) (*Tree, context.Context, error)
ResolveJSONWithContext calculate which will be the selected node according to the jsonRequest
func (*Tree) ResolveWithContext ¶ added in v0.3.1
func (t *Tree) ResolveWithContext(ctx context.Context, request map[string]interface{}, options ...func(t *TreeOptions)) (*Tree, context.Context, error)
ResolveWithContext calculate which will be the selected node according to the map request