matcher

package
v3.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetMatcherFactories

func GetMatcherFactories() map[string]func() ConditionMatcherFactory

GetMatcherFactories gets all create matcherFactory function

func GetSampleValueFromURL

func GetSampleValueFromURL(conditionKey string, sample map[string]string, param *common.URL, invocation protocol.Invocation) string

GetSampleValueFromURL returns the value of the conditionKey in the URL

func Match

func Match(condition Matcher, sample map[string]string, param *common.URL, invocation protocol.Invocation, isWhenCondition bool) bool

func SetMatcherFactory

func SetMatcherFactory(name string, fun func() ConditionMatcherFactory)

SetMatcherFactory sets create matcherFactory function with @name

Types

type ArgumentConditionMatcher

type ArgumentConditionMatcher struct {
	BaseConditionMatcher
}

ArgumentConditionMatcher analysis the arguments in the rule. Examples would be like this: "arguments[0]=1", whenCondition is that the first argument is equal to '1'. "arguments[1]=a", whenCondition is that the second argument is equal to 'a'.

func NewArgumentConditionMatcher

func NewArgumentConditionMatcher(key string) *ArgumentConditionMatcher

func (*ArgumentConditionMatcher) GetValue

func (a *ArgumentConditionMatcher) GetValue(sample map[string]string, url *common.URL, invocation protocol.Invocation) string

type ArgumentMatcherFactory

type ArgumentMatcherFactory struct {
}

ArgumentMatcherFactory matcher factory

func (*ArgumentMatcherFactory) NewMatcher

func (a *ArgumentMatcherFactory) NewMatcher(key string) Matcher

NewMatcher constructs a new matcher

func (*ArgumentMatcherFactory) Priority

func (a *ArgumentMatcherFactory) Priority() int64

func (*ArgumentMatcherFactory) ShouldMatch

func (a *ArgumentMatcherFactory) ShouldMatch(key string) bool

type AttachmentConditionMatcher

type AttachmentConditionMatcher struct {
	BaseConditionMatcher
}

AttachmentConditionMatcher analysis the attachments in the rule. Examples would be like this: "attachments[version]=1.0.0&attachments[timeout]=1000", whenCondition is that the version is equal to '1.0.0' and the timeout is equal to '1000'.

func NewAttachmentConditionMatcher

func NewAttachmentConditionMatcher(key string) *AttachmentConditionMatcher

func (*AttachmentConditionMatcher) GetValue

func (a *AttachmentConditionMatcher) GetValue(sample map[string]string, url *common.URL, invocation protocol.Invocation) string

type AttachmentMatcherFactory

type AttachmentMatcherFactory struct {
}

AttachmentMatcherFactory matcher factory

func (*AttachmentMatcherFactory) NewMatcher

func (a *AttachmentMatcherFactory) NewMatcher(key string) Matcher

NewMatcher constructs a new matcher

func (*AttachmentMatcherFactory) Priority

func (a *AttachmentMatcherFactory) Priority() int64

func (*AttachmentMatcherFactory) ShouldMatch

func (a *AttachmentMatcherFactory) ShouldMatch(key string) bool

type BaseConditionMatcher

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

BaseConditionMatcher records the match and mismatch patterns of this matcher while at the same time provides the common match logics.

func NewBaseConditionMatcher

func NewBaseConditionMatcher(key string) *BaseConditionMatcher

func (*BaseConditionMatcher) GetMatches

func (b *BaseConditionMatcher) GetMatches() map[string]struct{}

GetMatches returns matches.

func (*BaseConditionMatcher) GetMismatches

func (b *BaseConditionMatcher) GetMismatches() map[string]struct{}

GetMismatches returns misMatches.

func (*BaseConditionMatcher) GetValue

func (b *BaseConditionMatcher) GetValue(sample map[string]string, url *common.URL, invocation protocol.Invocation) string

GetValue returns a value from different places of the request context.

func (*BaseConditionMatcher) IsMatch

func (b *BaseConditionMatcher) IsMatch(value string, param *common.URL, invocation protocol.Invocation, isWhenCondition bool) bool

IsMatch indicates whether this matcher matches the patterns with request context.

type ConditionMatcherFactory

type ConditionMatcherFactory interface {
	// ShouldMatch indicates whether the key is of the form of the current matcher type which this factory instance represents.
	ShouldMatch(key string) bool
	// NewMatcher returns a matcher instance for the key.
	NewMatcher(key string) Matcher
	// Priority returns Priority in ConditionMatcherFactory
	// 0 to ^int(0) is better, smaller value by better priority.
	Priority() int64
}

func GetMatcherFactory

func GetMatcherFactory(name string) ConditionMatcherFactory

GetMatcherFactory gets create matcherFactory function by name

func NewArgumentMatcherFactory

func NewArgumentMatcherFactory() ConditionMatcherFactory

NewArgumentMatcherFactory constructs a new argument.ArgumentMatcherFactory

func NewAttachmentMatcherFactory

func NewAttachmentMatcherFactory() ConditionMatcherFactory

NewAttachmentMatcherFactory constructs a new attachment.AttachmentMatcherFactory

func NewParamMatcherFactory

func NewParamMatcherFactory() ConditionMatcherFactory

NewParamMatcherFactory constructs a new paramMatcherFactory

type Matcher

type Matcher interface {
	// IsMatch indicates whether this matcher matches the patterns with request context.
	IsMatch(value string, param *common.URL, invocation protocol.Invocation, isWhenCondition bool) bool
	// GetMatches returns matches.
	// match patterns extracted from when condition.
	GetMatches() map[string]struct{}
	// GetMismatches returns misMatches.
	// mismatch patterns extracted from then condition.
	GetMismatches() map[string]struct{}
	// GetValue returns a value from different places of the request context, for example, url, attachment and invocation.
	// This makes condition rule possible to check values in any place of a request.
	GetValue(sample map[string]string, url *common.URL, invocation protocol.Invocation) string
}

Matcher represents a specific match condition of a condition rule. The following condition rule 'foo=bar&arguments[0]=hello* => region=hangzhou' consists of three ConditionMatchers: 1. ParamConditionMatcher represented by 'foo=bar' 2. ArgumentConditionMatcher represented by 'arguments[0]=hello*' 3. ParamConditionMatcher represented by 'region=hangzhou'

type ParamConditionMatcher

type ParamConditionMatcher struct {
	BaseConditionMatcher
}

func NewParamConditionMatcher

func NewParamConditionMatcher(key string) *ParamConditionMatcher

func (*ParamConditionMatcher) GetValue

func (p *ParamConditionMatcher) GetValue(sample map[string]string, url *common.URL, invocation protocol.Invocation) string

type ParamMatcherFactory

type ParamMatcherFactory struct {
}

ParamMatcherFactory matcher factory

func (*ParamMatcherFactory) NewMatcher

func (p *ParamMatcherFactory) NewMatcher(key string) Matcher

NewMatcher constructs a new matcher

func (*ParamMatcherFactory) Priority

func (p *ParamMatcherFactory) Priority() int64

Priority make sure this is the last matcher being executed. This instance will be loaded separately to ensure it always gets executed as the last matcher.

func (*ParamMatcherFactory) ShouldMatch

func (p *ParamMatcherFactory) ShouldMatch(key string) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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