ngrules

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2019 License: Apache-2.0 Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

ngRules

This is a very minimal rules engine, it doesn't pretend to be a framework, just an easy way to validate struct's fields against a set of rule.

Dependencies

There are no external depdencies for this project, it's very simple.

Usage

You can check the test files, specially ngrules_test.go to see examples of how to use this library.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertRule

func AssertRule(entity interface{}, rule Rule) (valid bool, value interface{}, err error)

AssertRule validates if the rules is fullfilled the the entity

Types

type Operator

type Operator string

Operator defines an internal type for operator representation

const (
	OpEqual        Operator = "="
	OpNotEqual     Operator = "<>"
	OpGreater      Operator = ">"
	OpLower        Operator = "<"
	OpGreaterEqual Operator = ">="
	OpLowerEqual   Operator = "<="
)

Supported comparison operators

type Rule

type Rule struct {
	Name                string      // rule ID
	Property            string      // property name to check on the structure
	Condition           Operator    // condition operator
	ConditionValue      interface{} // value to be checked
	ReturnValuePositive interface{} // value returned if the condition is positive
	ReturnValueNegative interface{} // value returned if the condition fails
}

Rule represents a simple condition that needs to be applied on a given entity

Jump to

Keyboard shortcuts

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