Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HandleValidity ¶
HandleValidity extracts a value of type T from the given Context map. It returns the value and true if the key exists and the value has the correct type. If the key is missing or the type assertion fails, it returns the zero value of T and false.
Types ¶
type Rule ¶
Rule is an interface representing a boolean condition evaluator. Any type that implements Rule must provide the Eval method, which takes a Context and returns true or false depending on whether the context satisfies the rule.
func All ¶
All returns a Rule that evaluates to true only if all the provided rules evaluate to true. If any rule returns false, the combined rule returns false.
func Any ¶
Any returns a Rule that evaluates to true if at least one of the provided rules evaluates to true. If all rules return false, the combined rule returns false.
func Equals ¶
func Equals[T comparable](cField string, value T) Rule
Equals creates a Rule that checks if the value in Context at the given key is equal to the specified value of type T. The rule returns false if the key is missing or the type does not match.
func Greater ¶
Greater creates a Rule that checks if the value in Context at the given key is greater than the specified value of type T. T must satisfy cmp.Ordered (i.e., support >, <, >=, <=). The rule returns false if the key is missing or the type does not match.
type RuleFunction ¶
RuleFunction is a helper type that allows ordinary functions with the signature func(Context) bool to implement the Rule interface. By defining an Eval method, any RuleFunction can be used wherever a Rule is expected.
func (RuleFunction) Eval ¶
func (rf RuleFunction) Eval(c Context) bool
Eval calls the underlying function with the provided Context and returns its boolean result. This allows RuleFunction to satisfy the Rule interface.