discovery

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package discovery provides the interface for matching gRPC requests to upstreams.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Matches

type Matches []*Rule

Matches is a set of matches.

func (Matches) MatchMessage

func (m Matches) MatchMessage(bts []byte) (*Rule, bool)

MatchMessage matches the given gRPC request to a rule. It returns the first match and true if the request is matched.

func (Matches) NeedsDeeperMatch

func (m Matches) NeedsDeeperMatch() bool

NeedsDeeperMatch returns true if first RECV message is needed to match the request.

type Mock

type Mock struct {
	Header  metadata.MD
	Trailer metadata.MD
	Body    proto.Message
	Status  *status.Status
}

Mock contains the details of how the handler should reply to the downstream.

type Provider

type Provider interface {
	// Name returns the name of the provider.
	Name() string

	// Events returns the events of the routing rules.
	// It returns the name of the provider to update the routing rules.
	Events(ctx context.Context) <-chan string

	// Rules returns the routing rules.
	Rules(ctx context.Context) ([]*Rule, error)
}

Provider provides routing rules for the Service.

type ProviderMock

type ProviderMock struct {
	// EventsFunc mocks the Events method.
	EventsFunc func(ctx context.Context) <-chan string

	// NameFunc mocks the Name method.
	NameFunc func() string

	// RulesFunc mocks the Rules method.
	RulesFunc func(ctx context.Context) ([]*Rule, error)
	// contains filtered or unexported fields
}

ProviderMock is a mock implementation of Provider.

func TestSomethingThatUsesProvider(t *testing.T) {

	// make and configure a mocked Provider
	mockedProvider := &ProviderMock{
		EventsFunc: func(ctx context.Context) <-chan string {
			panic("mock out the Events method")
		},
		NameFunc: func() string {
			panic("mock out the Name method")
		},
		RulesFunc: func(ctx context.Context) ([]*Rule, error) {
			panic("mock out the Rules method")
		},
	}

	// use mockedProvider in code that requires Provider
	// and then make assertions.

}

func (*ProviderMock) Events

func (mock *ProviderMock) Events(ctx context.Context) <-chan string

Events calls EventsFunc.

func (*ProviderMock) EventsCalls

func (mock *ProviderMock) EventsCalls() []struct {
	Ctx context.Context
}

EventsCalls gets all the calls that were made to Events. Check the length with:

len(mockedProvider.EventsCalls())

func (*ProviderMock) Name

func (mock *ProviderMock) Name() string

Name calls NameFunc.

func (*ProviderMock) NameCalls

func (mock *ProviderMock) NameCalls() []struct {
}

NameCalls gets all the calls that were made to Name. Check the length with:

len(mockedProvider.NameCalls())

func (*ProviderMock) Rules

func (mock *ProviderMock) Rules(ctx context.Context) ([]*Rule, error)

Rules calls RulesFunc.

func (*ProviderMock) RulesCalls

func (mock *ProviderMock) RulesCalls() []struct {
	Ctx context.Context
}

RulesCalls gets all the calls that were made to Rules. Check the length with:

len(mockedProvider.RulesCalls())

type RequestMatcher

type RequestMatcher struct {
	// URI defines the fully-qualified method name, e.g.
	// "/package.Service/Method".
	URI *regexp.Regexp

	// IncomingMetadata contains the metadata of the incoming request.
	IncomingMetadata metadata.MD

	// Message contains the expected first RECV message of the request.
	Message proto.Message
}

RequestMatcher defines parameters to match the request to the rule.

func (RequestMatcher) Matches

func (r RequestMatcher) Matches(uri string, md metadata.MD) bool

Matches returns true if the request metadata is matched to the rule.

type Rule

type Rule struct {
	// Name is an optional name of the rule.
	Name string

	// Match defines the request matcher.
	// Any request that matches the matcher will be handled by the rule.
	Match RequestMatcher

	// Mock defines the details of how the handler should reply to the downstream.
	Mock *Mock
}

Rule is a routing rule for the Service.

func (*Rule) String

func (r *Rule) String() string

String returns the name of the rule.

type Service

type Service struct {
	Providers []Provider
	// contains filtered or unexported fields
}

Service provides routing rules for the Service.

func (*Service) MatchMetadata

func (s *Service) MatchMetadata(uri string, md metadata.MD) Matches

MatchMetadata matches the given gRPC request to an upstream connection.

func (*Service) Run

func (s *Service) Run(ctx context.Context) (err error)

Run starts a blocking loop that updates the routing rules on the signals, received from providers.

Directories

Path Synopsis
Package fileprovider provides a file-based discovery provider.
Package fileprovider provides a file-based discovery provider.

Jump to

Keyboard shortcuts

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