cond

package
v1.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package cond 提供了判断 bean 注册是否有效的条件。

Index

Constants

View Source
const (
	Or   = Operator(1) // 条件成立必须至少一个满足。
	And  = Operator(2) // 条件成立必须所有都要满足。
	None = Operator(3) // 条件成立必须没有一个满足。
)

Variables

This section is empty.

Functions

func Group

func Group(op Operator, cond ...Condition) *group

Group 返回基于条件组的 Condition 对象。

func New

func New() *conditional

New 返回 Condition 计算式对象。

func Not

func Not(c Condition) *not

Not 返回对一个条件取反后的 Condition 对象。

func On

func On(cond Condition) *conditional

On 返回一个以给定 Condition 为开始条件的计算式。

func OnBean

func OnBean(selector bean.Selector) *conditional

OnBean 返回一个以 onBean 为开始条件的计算式。

func OnExpression

func OnExpression(expression string) *conditional

OnExpression 返回一个以 onExpression 为开始条件的计算式。

func OnMatches

func OnMatches(fn Matches) *conditional

OnMatches 返回一个以 onMatches 为开始条件的计算式。

func OnMissingBean

func OnMissingBean(selector bean.Selector) *conditional

OnMissingBean 返回一个以 onMissingBean 为开始条件的计算式。

func OnProfile

func OnProfile(profile string) *conditional

OnProfile 返回一个以 spring.profile 属性值是否匹配为开始条件的计算式。

func OnProperty

func OnProperty(name string, options ...PropertyOption) *conditional

OnProperty 返回一个以 onProperty 为开始条件的计算式。

func OnSingleCandidate

func OnSingleCandidate(selector bean.Selector) *conditional

OnSingleCandidate 返回一个以 onSingleCandidate 为开始条件的计算式。

Types

type Condition

type Condition interface {
	Matches(ctx Context) (bool, error)
}

Condition 条件接口,条件成立 Matches 方法返回 true,否则返回 false。

type Context

type Context interface {

	// Prop 获取 key 对应的属性值,注意 key 是大小写敏感的。当 key 对应的属性
	// 值存在时,或者 key 对应的属性值不存在但设置了默认值时,该方法返回 string
	// 类型的数据,当 key 对应的属性值不存在且没有设置默认值时该方法返回 nil。
	// 因此可以通过判断该方法的返回值是否为 nil 来判断 key 对应的属性值是否存在。
	Prop(key string, opts ...conf.GetOption) interface{}

	// Find 查找符合条件的 bean 对象,注意该函数只能保证返回的 bean 是有效的,
	// 即未被标记为删除的,而不能保证已经完成属性绑定和依赖注入。
	Find(selector bean.Selector) ([]bean.Definition, error)
}

Context IoC 容器对 cond 模块提供的最小功能集。

type Matches

type Matches func(ctx Context) (bool, error)

type Operator

type Operator int

Operator 条件操作符,包含 Or、And、None 三种。

type PropertyOption

type PropertyOption func(*onProperty)

func HavingValue

func HavingValue(havingValue string) PropertyOption

HavingValue 当 havingValue 与属性值相同时条件成立。

func MatchIfMissing

func MatchIfMissing() PropertyOption

MatchIfMissing 当属性不存在时条件成立。

Jump to

Keyboard shortcuts

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