router

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2021 License: Apache-2.0 Imports: 25 Imported by: 8

Documentation

Index

Constants

View Source
const RouterLogFormat = "[router] [%s] [%s] %v"

[sub module] & [function] & msg

Variables

View Source
var (
	ErrNilRouterConfig      = errors.New("router config is nil")
	ErrNoVirtualHost        = errors.New("virtual host is nil")
	ErrNoRouters            = errors.New("routers is nil")
	ErrDuplicateVirtualHost = errors.New("duplicate domain virtual host")
	ErrUnexpected           = errors.New("an unexpected error occurs")
)

Functions

func CreateCommonHeaderMatcher added in v0.21.0

func CreateCommonHeaderMatcher(headers []v2.HeaderMatcher) types.HeaderMatcher

func CreateHTTPHeaderMatcher added in v0.21.0

func CreateHTTPHeaderMatcher(headers []v2.HeaderMatcher) types.HeaderMatcher

CreateHTTPHeaderMatcher creates a http header matcher as a types.HeaderMatcher

func DefaultMakeHandler added in v0.20.0

func DefaultMakeHandler(ctx context.Context, headers api.HeaderMap, routers types.Routers) types.RouteHandler

func GetRoutersMangerInstance

func GetRoutersMangerInstance() types.RouterManager

compatible

func MakeHandlerFuncExists added in v0.20.0

func MakeHandlerFuncExists(name string) bool

func NewConfigImpl

func NewConfigImpl(routerConfig *v2.RouterConfiguration) *configImpl

NewConfigImpl return an configImpl instance contains requestHeadersParser and responseHeadersParser

func NewRouteBase added in v0.21.0

func NewRouteBase(vh api.VirtualHost, route *v2.Router) (api.RouteBase, error)

func NewRouterManager

func NewRouterManager() types.RouterManager

func NewRouters

func NewRouters(routerConfig *v2.RouterConfiguration) (types.Routers, error)

NewRouters creates a types.Routers by according to config

func RegisterMakeHandler added in v0.20.0

func RegisterMakeHandler(name string, f MakeHandlerFunc, isDefault bool)

Types

type BaseHTTPRouteRule added in v0.21.0

type BaseHTTPRouteRule struct {
	*RouteRuleImplBase
	// contains filtered or unexported fields
}

func NewBaseHTTPRouteRule added in v0.21.0

func NewBaseHTTPRouteRule(base *RouteRuleImplBase, headers []v2.HeaderMatcher) *BaseHTTPRouteRule

func (*BaseHTTPRouteRule) HeaderMatchCriteria added in v0.21.0

func (rri *BaseHTTPRouteRule) HeaderMatchCriteria() api.KeyValueMatchCriteria

type DslExpressionRouteRuleImpl added in v0.21.0

type DslExpressionRouteRuleImpl struct {
	*RouteRuleImplBase
	DslExpressions []attribute.Expression
	// contains filtered or unexported fields
}

func (*DslExpressionRouteRuleImpl) FinalizeRequestHeaders added in v0.21.0

func (drri *DslExpressionRouteRuleImpl) FinalizeRequestHeaders(ctx context.Context, headers api.HeaderMap, requestInfo api.RequestInfo)

func (*DslExpressionRouteRuleImpl) HeaderMatchCriteria added in v0.21.0

func (drri *DslExpressionRouteRuleImpl) HeaderMatchCriteria() api.KeyValueMatchCriteria

func (*DslExpressionRouteRuleImpl) Match added in v0.21.0

func (drri *DslExpressionRouteRuleImpl) Match(ctx context.Context, headers api.HeaderMap) api.Route

func (*DslExpressionRouteRuleImpl) MatchType added in v0.21.0

func (drri *DslExpressionRouteRuleImpl) MatchType() api.PathMatchType

func (*DslExpressionRouteRuleImpl) Matcher added in v0.21.0

func (drri *DslExpressionRouteRuleImpl) Matcher() string

func (*DslExpressionRouteRuleImpl) PathMatchCriterion added in v0.21.0

func (drri *DslExpressionRouteRuleImpl) PathMatchCriterion() api.PathMatchCriterion

func (*DslExpressionRouteRuleImpl) RouteRule added in v0.21.0

func (drri *DslExpressionRouteRuleImpl) RouteRule() api.RouteRule

type KeyValueData added in v0.21.0

type KeyValueData struct {
	Name  string // name should be lower case in router headerdata
	Value StringMatch
}

KeyValueData represents a key-value pairs. The value is a StringMatch used in HeaderMatch and QueryParamsMatch

func NewKeyValueData added in v0.21.0

func NewKeyValueData(header v2.HeaderMatcher) (*KeyValueData, error)

func (*KeyValueData) Key added in v0.21.0

func (k *KeyValueData) Key() string

func (*KeyValueData) MatchType added in v0.21.0

func (k *KeyValueData) MatchType() api.KeyValueMatchType

func (*KeyValueData) Matcher added in v0.21.0

func (k *KeyValueData) Matcher() string

type MakeHandlerFunc added in v0.20.0

type MakeHandlerFunc func(ctx context.Context, headers api.HeaderMap, routers types.Routers) types.RouteHandler

MakeHandlerFunc creates a router handler for mosn

func GetMakeHandlerFunc added in v0.20.0

func GetMakeHandlerFunc(name string) MakeHandlerFunc

func (MakeHandlerFunc) DoRouteHandler added in v0.20.0

func (factory MakeHandlerFunc) DoRouteHandler(ctx context.Context, headers api.HeaderMap, routers types.Routers, clusterManager types.ClusterManager) (types.ClusterSnapshot, api.Route)

type MetadataMatchCriteriaImpl

type MetadataMatchCriteriaImpl struct {
	MatchCriteriaArray []api.MetadataMatchCriterion
}

MetadataMatchCriteriaImpl class wrapper MatchCriteriaArray which contains MatchCriteria in dictionary sorted

func NewMetadataMatchCriteriaImpl

func NewMetadataMatchCriteriaImpl(metadataMatches map[string]string) *MetadataMatchCriteriaImpl

NewMetadataMatchCriteriaImpl

func (*MetadataMatchCriteriaImpl) Len

func (mmcti *MetadataMatchCriteriaImpl) Len() int

func (*MetadataMatchCriteriaImpl) Less

func (mmcti *MetadataMatchCriteriaImpl) Less(i, j int) bool

func (*MetadataMatchCriteriaImpl) MergeMatchCriteria

func (mmcti *MetadataMatchCriteriaImpl) MergeMatchCriteria(metadataMatches map[string]interface{}) api.MetadataMatchCriteria

MergeMatchCriteria No usage currently

func (*MetadataMatchCriteriaImpl) MetadataMatchCriteria

func (mmcti *MetadataMatchCriteriaImpl) MetadataMatchCriteria() []api.MetadataMatchCriterion

MetadataMatchCriteria

func (*MetadataMatchCriteriaImpl) Swap

func (mmcti *MetadataMatchCriteriaImpl) Swap(i, j int)

type MetadataMatchCriterionImpl

type MetadataMatchCriterionImpl struct {
	Name  string
	Value string
}

MetadataMatchCriterionImpl class contains the name and value of the metadata match criterion Implement types.MetadataMatchCriterion

func (*MetadataMatchCriterionImpl) MetadataKeyName

func (mmci *MetadataMatchCriterionImpl) MetadataKeyName() string

MetadataKeyName return name

func (*MetadataMatchCriterionImpl) MetadataValue

func (mmci *MetadataMatchCriterionImpl) MetadataValue() string

MetadataValue return value

type Model added in v0.20.0

type Model string
const (
	AND Model = "and"
	OR  Model = "or"
)

type PathRouteRuleImpl

type PathRouteRuleImpl struct {
	*BaseHTTPRouteRule
	// contains filtered or unexported fields
}

func (*PathRouteRuleImpl) FinalizeRequestHeaders

func (prri *PathRouteRuleImpl) FinalizeRequestHeaders(ctx context.Context, headers api.HeaderMap, requestInfo api.RequestInfo)

types.RouteRule override Base

func (*PathRouteRuleImpl) Match

func (prri *PathRouteRuleImpl) Match(ctx context.Context, headers api.HeaderMap) api.Route

func (*PathRouteRuleImpl) MatchType

func (prri *PathRouteRuleImpl) MatchType() api.PathMatchType

func (*PathRouteRuleImpl) Matcher

func (prri *PathRouteRuleImpl) Matcher() string

types.PathMatchCriterion

func (*PathRouteRuleImpl) PathMatchCriterion

func (prri *PathRouteRuleImpl) PathMatchCriterion() api.PathMatchCriterion

func (*PathRouteRuleImpl) RouteRule

func (prri *PathRouteRuleImpl) RouteRule() api.RouteRule

type PrefixRouteRuleImpl

type PrefixRouteRuleImpl struct {
	*BaseHTTPRouteRule
	// contains filtered or unexported fields
}

PrefixRouteRuleImpl used to "match path" with "prefix match"

func (*PrefixRouteRuleImpl) FinalizeRequestHeaders

func (prei *PrefixRouteRuleImpl) FinalizeRequestHeaders(ctx context.Context, headers api.HeaderMap, requestInfo api.RequestInfo)

types.RouteRule override Base

func (*PrefixRouteRuleImpl) Match

func (prei *PrefixRouteRuleImpl) Match(ctx context.Context, headers api.HeaderMap) api.Route

func (*PrefixRouteRuleImpl) MatchType

func (prei *PrefixRouteRuleImpl) MatchType() api.PathMatchType

func (*PrefixRouteRuleImpl) Matcher

func (prei *PrefixRouteRuleImpl) Matcher() string

types.PathMatchCriterion

func (*PrefixRouteRuleImpl) PathMatchCriterion

func (prei *PrefixRouteRuleImpl) PathMatchCriterion() api.PathMatchCriterion

func (*PrefixRouteRuleImpl) RouteRule

func (prei *PrefixRouteRuleImpl) RouteRule() api.RouteRule

type RPCRouteRuleImpl added in v0.21.0

type RPCRouteRuleImpl struct {
	*RouteRuleImplBase
	// contains filtered or unexported fields
}

SofaRule supports only simple headers match. and use fastmatch for compatible old mode

func (*RPCRouteRuleImpl) FinalizeRequestHeaders added in v0.21.0

func (srri *RPCRouteRuleImpl) FinalizeRequestHeaders(ctx context.Context, headers api.HeaderMap, requestInfo api.RequestInfo)

func (*RPCRouteRuleImpl) HeaderMatchCriteria added in v0.21.0

func (srri *RPCRouteRuleImpl) HeaderMatchCriteria() api.KeyValueMatchCriteria

func (*RPCRouteRuleImpl) Match added in v0.21.0

func (srri *RPCRouteRuleImpl) Match(ctx context.Context, headers api.HeaderMap) api.Route

func (*RPCRouteRuleImpl) MatchType added in v0.21.0

func (srri *RPCRouteRuleImpl) MatchType() api.PathMatchType

func (*RPCRouteRuleImpl) Matcher added in v0.21.0

func (srri *RPCRouteRuleImpl) Matcher() string

func (*RPCRouteRuleImpl) PathMatchCriterion added in v0.21.0

func (srri *RPCRouteRuleImpl) PathMatchCriterion() api.PathMatchCriterion

func (*RPCRouteRuleImpl) RouteRule added in v0.21.0

func (srri *RPCRouteRuleImpl) RouteRule() api.RouteRule

type RegexRouteRuleImpl

type RegexRouteRuleImpl struct {
	*BaseHTTPRouteRule
	// contains filtered or unexported fields
}

RegexRouteRuleImpl used to "match path" with "regex match"

func (*RegexRouteRuleImpl) FinalizeRequestHeaders

func (rrei *RegexRouteRuleImpl) FinalizeRequestHeaders(ctx context.Context, headers api.HeaderMap, requestInfo api.RequestInfo)

func (*RegexRouteRuleImpl) Match

func (rrei *RegexRouteRuleImpl) Match(ctx context.Context, headers api.HeaderMap) api.Route

func (*RegexRouteRuleImpl) MatchType

func (rrei *RegexRouteRuleImpl) MatchType() api.PathMatchType

func (*RegexRouteRuleImpl) Matcher

func (rrei *RegexRouteRuleImpl) Matcher() string

func (*RegexRouteRuleImpl) PathMatchCriterion

func (rrei *RegexRouteRuleImpl) PathMatchCriterion() api.PathMatchCriterion

func (*RegexRouteRuleImpl) RouteRule

func (rrei *RegexRouteRuleImpl) RouteRule() api.RouteRule

type RouteBase

type RouteBase = api.RouteBase

func CreateRPCRule added in v0.21.0

func CreateRPCRule(base *RouteRuleImplBase, headers []v2.HeaderMatcher) RouteBase

type RouteRuleImplBase

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

func NewRouteRuleImplBase

func NewRouteRuleImplBase(vHost api.VirtualHost, route *v2.Router) (*RouteRuleImplBase, error)

func (*RouteRuleImplBase) ClusterName

func (rri *RouteRuleImplBase) ClusterName() string

types.RouteRule Select Cluster for Routing if weighted cluster is nil, return clusterName directly, else select cluster from weighted-clusters

func (*RouteRuleImplBase) DirectResponseRule

func (rri *RouteRuleImplBase) DirectResponseRule() api.DirectResponseRule

func (*RouteRuleImplBase) FinalizePathHeader added in v0.15.0

func (rri *RouteRuleImplBase) FinalizePathHeader(ctx context.Context, headers api.HeaderMap, matchedPath string)

func (*RouteRuleImplBase) FinalizeRequestHeaders

func (rri *RouteRuleImplBase) FinalizeRequestHeaders(ctx context.Context, headers api.HeaderMap, requestInfo api.RequestInfo)

func (*RouteRuleImplBase) FinalizeResponseHeaders

func (rri *RouteRuleImplBase) FinalizeResponseHeaders(ctx context.Context, headers api.HeaderMap, requestInfo api.RequestInfo)

func (*RouteRuleImplBase) GlobalTimeout

func (rri *RouteRuleImplBase) GlobalTimeout() time.Duration

func (*RouteRuleImplBase) MetadataMatchCriteria

func (rri *RouteRuleImplBase) MetadataMatchCriteria(clusterName string) api.MetadataMatchCriteria

func (*RouteRuleImplBase) PerFilterConfig

func (rri *RouteRuleImplBase) PerFilterConfig() map[string]interface{}

func (*RouteRuleImplBase) Policy

func (rri *RouteRuleImplBase) Policy() api.Policy

func (*RouteRuleImplBase) RedirectRule added in v0.15.0

func (rri *RouteRuleImplBase) RedirectRule() api.RedirectRule

func (*RouteRuleImplBase) UpstreamProtocol

func (rri *RouteRuleImplBase) UpstreamProtocol() string

func (*RouteRuleImplBase) VirtualHost added in v0.21.0

func (rri *RouteRuleImplBase) VirtualHost() api.VirtualHost

type RouterRuleFactory

type RouterRuleFactory func(base *RouteRuleImplBase, header []v2.HeaderMatcher) RouteBase

RouterRuleFactory creates a RouteBase

type RoutersWrapper

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

func (*RoutersWrapper) GetRouters

func (rw *RoutersWrapper) GetRouters() types.Routers

func (*RoutersWrapper) GetRoutersConfig

func (rw *RoutersWrapper) GetRoutersConfig() v2.RouterConfiguration

type StringMatch added in v0.21.0

type StringMatch struct {
	Value        string
	IsRegex      bool
	RegexPattern *regexp.Regexp
}

StringMatch describes hwo to match a given string. support regex-based match or exact string match (case-sensitive)

func (StringMatch) Matches added in v0.21.0

func (sm StringMatch) Matches(s string) bool

type VariableMatchItem added in v0.20.0

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

func ParseToVariableMatchItem added in v0.20.0

func ParseToVariableMatchItem(matcher v2.VariableMatcher) *VariableMatchItem

type VariableRouteRuleImpl added in v0.20.0

type VariableRouteRuleImpl struct {
	*RouteRuleImplBase
	Variables []*VariableMatchItem
}

func (*VariableRouteRuleImpl) FinalizeRequestHeaders added in v0.20.0

func (vrri *VariableRouteRuleImpl) FinalizeRequestHeaders(ctx context.Context, headers api.HeaderMap, requestInfo api.RequestInfo)

func (*VariableRouteRuleImpl) HeaderMatchCriteria added in v0.21.0

func (vrri *VariableRouteRuleImpl) HeaderMatchCriteria() api.KeyValueMatchCriteria

func (*VariableRouteRuleImpl) Match added in v0.20.0

func (vrri *VariableRouteRuleImpl) Match(ctx context.Context, headers api.HeaderMap) api.Route

func (*VariableRouteRuleImpl) MatchType added in v0.20.0

func (vrri *VariableRouteRuleImpl) MatchType() api.PathMatchType

func (*VariableRouteRuleImpl) Matcher added in v0.20.0

func (vrri *VariableRouteRuleImpl) Matcher() string

func (*VariableRouteRuleImpl) PathMatchCriterion added in v0.20.0

func (vrri *VariableRouteRuleImpl) PathMatchCriterion() api.PathMatchCriterion

func (*VariableRouteRuleImpl) RouteRule added in v0.20.0

func (vrri *VariableRouteRuleImpl) RouteRule() api.RouteRule

type VirtualHostImpl

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

func NewVirtualHostImpl

func NewVirtualHostImpl(virtualHost *v2.VirtualHost) (*VirtualHostImpl, error)

NewVirtualHostImpl convert mosn VirtualHost config to actual virtual host object

func (*VirtualHostImpl) AddRoute

func (vh *VirtualHostImpl) AddRoute(route api.RouteBase) error

func (*VirtualHostImpl) FinalizeRequestHeaders added in v0.21.0

func (vh *VirtualHostImpl) FinalizeRequestHeaders(ctx context.Context, headers api.HeaderMap, requestInfo api.RequestInfo)

func (*VirtualHostImpl) FinalizeResponseHeaders added in v0.21.0

func (vh *VirtualHostImpl) FinalizeResponseHeaders(ctx context.Context, headers api.HeaderMap, requestInfo api.RequestInfo)

func (*VirtualHostImpl) GetAllRoutesFromEntries

func (vh *VirtualHostImpl) GetAllRoutesFromEntries(ctx context.Context, headers api.HeaderMap) []api.Route

func (*VirtualHostImpl) GetRouteFromEntries

func (vh *VirtualHostImpl) GetRouteFromEntries(ctx context.Context, headers api.HeaderMap) api.Route

func (*VirtualHostImpl) GetRouteFromHeaderKV

func (vh *VirtualHostImpl) GetRouteFromHeaderKV(key, value string) api.Route

func (*VirtualHostImpl) Name

func (vh *VirtualHostImpl) Name() string

func (*VirtualHostImpl) PerFilterConfig added in v0.21.0

func (vh *VirtualHostImpl) PerFilterConfig() map[string]interface{}

func (*VirtualHostImpl) RemoveAllRoutes

func (vh *VirtualHostImpl) RemoveAllRoutes()

Jump to

Keyboard shortcuts

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