cond

package
v0.0.0-...-bd77e7c Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package cond provides many conditions used when registering bean.

Package cond is a generated GoMock package.

Index

Constants

View Source
const (
	Or   = Operator(1) // at least one of the conditions must be met.
	And  = Operator(2) // all conditions must be met.
	None = Operator(3) // all conditions must be not met.
)

Variables

View Source
var UnimplementedMethod = errors.New("unimplemented method")

UnimplementedMethod throws this error when calling an unimplemented method.

Functions

func New

func New() *conditional

New returns a Condition implemented by link of Condition(s).

func On

func On(cond Condition) *conditional

On returns a conditional that starts with one Condition.

func OnBean

func OnBean(selector BeanSelector) *conditional

OnBean returns a conditional that starts with a Condition that returns true when finding more than one beans.

func OnExpression

func OnExpression(expression string) *conditional

OnExpression returns a conditional that starts with a Condition that returns true when an expression returns true.

func OnMatches

func OnMatches(fn func(ctx Context) (bool, error)) *conditional

OnMatches returns a conditional that starts with a Condition that returns true when function returns true.

func OnMissingBean

func OnMissingBean(selector BeanSelector) *conditional

OnMissingBean returns a conditional that starts with a Condition that returns true when finding no beans.

func OnMissingProperty

func OnMissingProperty(name string) *conditional

OnMissingProperty returns a conditional that starts with a Condition that returns true when property doesn't exist.

func OnProfile

func OnProfile(profile string) *conditional

OnProfile returns a conditional that starts with a Condition that returns true when property value equals to profile.

func OnProperty

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

OnProperty returns a conditional that starts with a Condition that checks a property and its value.

func OnSingleBean

func OnSingleBean(selector BeanSelector) *conditional

OnSingleBean returns a conditional that starts with a Condition that returns true when finding only one bean.

Types

type BeanDefinition

type BeanDefinition = utils.BeanDefinition

type BeanSelector

type BeanSelector = utils.BeanSelector

type Condition

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

Condition is used when registering a bean to determine whether it's valid.

func Group

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

Group returns a Condition implemented by operation of Condition(s).

func Not

func Not(c Condition) Condition

Not returns a Condition that negating to another.

func OK

func OK() Condition

OK returns a Condition that always returns true.

type Context

type Context interface {
	// Has returns whether the IoC container has a property.
	Has(key string) bool
	// Prop returns the property's value when the IoC container has it, or
	// returns empty string when the IoC container doesn't have it.
	Prop(key string, opts ...conf.GetOption) string
	// Find returns bean definitions that matched with the bean selector.
	Find(selector BeanSelector) ([]BeanDefinition, error)
}

Context defines some methods of IoC container that conditions use.

type FuncCond

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

func (FuncCond) Matches

func (c FuncCond) Matches(ctx Context) (bool, error)

type MockCondition

type MockCondition struct {
	// contains filtered or unexported fields
}

MockCondition is a mock of Condition interface.

func NewMockCondition

func NewMockCondition(ctrl *gomock.Controller) *MockCondition

NewMockCondition creates a new mock instance.

func (*MockCondition) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockCondition) Matches

func (m *MockCondition) Matches(ctx Context) (bool, error)

Matches mocks base method.

type MockConditionMockRecorder

type MockConditionMockRecorder struct {
	// contains filtered or unexported fields
}

MockConditionMockRecorder is the mock recorder for MockCondition.

func (*MockConditionMockRecorder) Matches

func (mr *MockConditionMockRecorder) Matches(ctx interface{}) *gomock.Call

Matches indicates an expected call of Matches.

type MockContext

type MockContext struct {
	// contains filtered or unexported fields
}

MockContext is a mock of Context interface.

func NewMockContext

func NewMockContext(ctrl *gomock.Controller) *MockContext

NewMockContext creates a new mock instance.

func (*MockContext) EXPECT

func (m *MockContext) EXPECT() *MockContextMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockContext) Find

func (m *MockContext) Find(selector BeanSelector) ([]BeanDefinition, error)

Find mocks base method.

func (*MockContext) Has

func (m *MockContext) Has(key string) bool

Has mocks base method.

func (*MockContext) Prop

func (m *MockContext) Prop(key string, opts ...conf.GetOption) string

Prop mocks base method.

type MockContextMockRecorder

type MockContextMockRecorder struct {
	// contains filtered or unexported fields
}

MockContextMockRecorder is the mock recorder for MockContext.

func (*MockContextMockRecorder) Find

func (mr *MockContextMockRecorder) Find(selector interface{}) *gomock.Call

Find indicates an expected call of Find.

func (*MockContextMockRecorder) Has

func (mr *MockContextMockRecorder) Has(key interface{}) *gomock.Call

Has indicates an expected call of Has.

func (*MockContextMockRecorder) Prop

func (mr *MockContextMockRecorder) Prop(key interface{}, opts ...interface{}) *gomock.Call

Prop indicates an expected call of Prop.

type Operator

type Operator int

Operator defines operation between conditions, including Or、And、None.

type PropertyOption

type PropertyOption func(*onProperty)

func HavingValue

func HavingValue(havingValue string) PropertyOption

HavingValue sets a Condition to return true when property value equals to havingValue.

func MatchIfMissing

func MatchIfMissing() PropertyOption

MatchIfMissing sets a Condition to return true when property doesn't exist.

Jump to

Keyboard shortcuts

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