gs_cond

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func And

func And(conditions ...gs.Condition) gs.Condition

And combines multiple conditions with an AND operator, returning true if all conditions are satisfied.

func EvalExpr

func EvalExpr(input string, val string) (bool, error)

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

func FormatGroup(op string, conditions []gs.Condition) string

FormatGroup generates a formatted string for a group of conditions (AND, OR, NONE).

func None

func None(conditions ...gs.Condition) gs.Condition

None combines multiple conditions with a NONE operator, returning true if none of the conditions are satisfied.

func Not

func Not(c gs.Condition) gs.Condition

Not creates a condition that inverts the result of the provided condition.

func OnBean

func OnBean[T any](name ...string) gs.Condition

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

func OnExpression(expression string) gs.Condition

OnExpression creates a condition that evaluates based on a custom string expression. The expression is expected to return true or false.

func OnFunc

func OnFunc(fn func(ctx gs.ConditionContext) (bool, error)) gs.Condition

OnFunc creates a Conditional that evaluates using a custom function.

func OnMissingBean

func OnMissingBean[T any](name ...string) gs.Condition

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

func OnSingleBean[T any](name ...string) gs.Condition

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

func Or(conditions ...gs.Condition) gs.Condition

Or combines multiple conditions with an OR operator, returning true if at least one condition is satisfied.

func RegisterExpressFunc

func RegisterExpressFunc(name string, fn any)

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.

Jump to

Keyboard shortcuts

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