Documentation
¶
Overview ¶
Package gs_cond provides conditional component registration for Go-Spring framework, offering runtime decision-making through various condition types.
1. Property Conditions
Existence check: cond := OnProperty("db.host")
Value matching: cond := OnProperty("env").HavingValue("prod")
Expression evaluation: cond := OnProperty("port").HavingValue("expr:int($) > 1024")
Missing handling: cond := OnProperty("debug").MatchIfMissing()
2. Bean Conditions
Existence verification: cond := OnBean[Database]()
Absence check: cond := OnMissingBean[Logger]()
Singleton validation: cond := OnSingleBean[Config]()
3. Logical Combinators
Conjunction: cond := And(condition1, condition2)
Disjunction: cond := Or(condition1, condition2)
Negation: cond := Not(condition)
Universal negation: cond := None(condition1, condition2)
4. Custom Conditions
Functional condition: cond := OnFunc(func(ctx gs.ConditionContext) (bool, error) { return time.Now().Hour() > 9, nil })
Expression condition (Pending implementation): cond := OnExpression("beans('redis').size() > 0")
Index ¶
- func And(conditions ...gs.Condition) gs.Condition
- func EvalExpr(input string, val string) (bool, error)
- func FormatGroup(op string, conditions []gs.Condition) string
- func None(conditions ...gs.Condition) gs.Condition
- func Not(c gs.Condition) gs.Condition
- func OnBean[T any](name ...string) gs.Condition
- func OnBeanSelector(s gs.BeanSelector) gs.Condition
- func OnExpression(expression string) gs.Condition
- func OnFunc(fn func(ctx gs.ConditionContext) (bool, error)) gs.Condition
- func OnMissingBean[T any](name ...string) gs.Condition
- func OnMissingBeanSelector(s gs.BeanSelector) gs.Condition
- func OnSingleBean[T any](name ...string) gs.Condition
- func OnSingleBeanSelector(s gs.BeanSelector) gs.Condition
- func Or(conditions ...gs.Condition) gs.Condition
- func RegisterExpressFunc(name string, fn any)
- type ConditionOnProperty
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func And ¶
And combines multiple conditions with an AND operator, returning true if all conditions are satisfied.
func EvalExpr ¶
EvalExpr evaluates a boolean expression using the provided value as the "$" variable. `input` is a boolean expression string to evaluate, it must return a boolean result. `val` is a string value accessible as "$" within the expression context.
func FormatGroup ¶
FormatGroup generates a formatted string for a group of conditions (AND, OR, NONE).
func None ¶
None combines multiple conditions with a NONE operator, returning true if none of the conditions are satisfied.
func OnBean ¶
OnBean creates a condition that evaluates to true if at least one bean matches the specified type and name.
func OnBeanSelector ¶
func OnBeanSelector(s gs.BeanSelector) gs.Condition
OnBeanSelector creates a condition that evaluates to true if at least one bean matches the provided selector.
func OnExpression ¶
OnExpression creates a condition that evaluates based on a custom string expression. The expression is expected to return true or false.
func OnMissingBean ¶
OnMissingBean creates a condition that evaluates to true if no beans match the specified type and name.
func OnMissingBeanSelector ¶
func OnMissingBeanSelector(s gs.BeanSelector) gs.Condition
OnMissingBeanSelector creates a condition that evaluates to true if no beans match the provided selector.
func OnSingleBean ¶
OnSingleBean creates a condition that evaluates to true if exactly one bean matches the specified type and name.
func OnSingleBeanSelector ¶
func OnSingleBeanSelector(s gs.BeanSelector) gs.Condition
OnSingleBeanSelector creates a condition that evaluates to true if exactly one bean matches the provided selector.
func Or ¶
Or combines multiple conditions with an OR operator, returning true if at least one condition is satisfied.
func RegisterExpressFunc ¶
RegisterExpressFunc registers a function under the given name, making it available for use in expressions evaluated by EvalExpr. Functions must be registered before they are referenced in any expression.
Types ¶
type ConditionOnProperty ¶ added in v1.2.3
type ConditionOnProperty interface { gs.Condition MatchIfMissing() ConditionOnProperty HavingValue(s string) ConditionOnProperty }
ConditionOnProperty defines the methods for evaluating a condition based on a property. This interface provides flexibility for matching missing properties and checking their values.
func OnProperty ¶
func OnProperty(name string) ConditionOnProperty
OnProperty creates a condition based on the presence and value of a specified property.