Documentation
¶
Overview ¶
Package gs_cond provides a set of composable conditions used to control bean registration for Go-Spring framework.
It defines various condition types such as:
- OnFunc: Uses a custom function to evaluate a condition.
- OnProperty: Matches based on the presence or value of a property.
- OnBean: Matches if at least one bean exists for a given selector.
- OnMissingBean: Matches if no beans exist for a given selector.
- OnSingleBean: Matches if exactly one bean exists for a given selector.
- OnExpression: Evaluates a custom expression (currently unimplemented).
- Not / Or / And / None: Logical combinators for composing multiple conditions.
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 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 formats a group of conditions (e.g., AND, OR, NONE) as a string for debugging and logging purposes.
func None ¶
None combines multiple conditions using NONE logic. Returns true only if all conditions are false.
func OnBean ¶
OnBean creates a condition that evaluates to true if at least one bean matches the specified type and optional 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 a custom boolean expression.
func OnMissingBean ¶
OnMissingBean creates a condition that evaluates to true if no bean matches the given type and optional name.
func OnMissingBeanSelector ¶
func OnMissingBeanSelector(s gs.BeanSelector) gs.Condition
OnMissingBeanSelector creates a condition that evaluates to true if no bean matches the provided selector.
func OnSingleBean ¶
OnSingleBean creates a condition that evaluates to true if exactly one bean matches the given type and optional 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 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 // Match if the property is missing HavingValue(s string) ConditionOnProperty // Match if the property has a specific value }
ConditionOnProperty defines a condition that is evaluated based on the value of a property in the application context. It provides methods to customize behavior for missing properties and specific property values.
func OnProperty ¶
func OnProperty(name string) ConditionOnProperty
OnProperty creates a new condition that checks for the presence and/or value of a specified property.