discovery

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package discovery provides a common interface for all providers and Match to transform source to destination URL. Run func starts event loop checking all providers and retrieving lists of rules. All lists combined into a merged one.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains added in v0.3.0

func Contains(e string, s []string) bool

Contains checks if the input string (e) in the given slice

Types

type MatchType added in v0.3.0

type MatchType int

MatchType defines the type of mapper (rule)

const (
	MTProxy MatchType = iota
	MTStatic
)

enum of all match types

func (MatchType) String added in v0.3.0

func (m MatchType) String() string

type Provider

type Provider interface {
	Events(ctx context.Context) (res <-chan ProviderID)
	List() (res []URLMapper, err error)
}

Provider defines sources of mappers

type ProviderID

type ProviderID string

ProviderID holds provider identifier to emulate enum of them

const (
	PIDocker ProviderID = "docker"
	PIStatic ProviderID = "static"
	PIFile   ProviderID = "file"
)

enum of all provider ids

type ProviderMock

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

	// ListFunc mocks the List method.
	ListFunc func() ([]URLMapper, 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 ProviderID {
			panic("mock out the Events method")
		},
		ListFunc: func() ([]URLMapper, error) {
			panic("mock out the List method")
		},
	}

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

}

func (*ProviderMock) Events

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

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) List

func (mock *ProviderMock) List() ([]URLMapper, error)

List calls ListFunc.

func (*ProviderMock) ListCalls

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

ListCalls gets all the calls that were made to List. Check the length with:

len(mockedProvider.ListCalls())

type Service

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

Service implements discovery with multiple providers and url matcher

func NewService

func NewService(providers []Provider, interval time.Duration) *Service

NewService makes service with given providers

func (*Service) Mappers

func (s *Service) Mappers() (mappers []URLMapper)

Mappers return list of all mappers

func (*Service) Match

func (s *Service) Match(srv, src string) (string, MatchType, bool)

Match url to all mappers

func (*Service) Run

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

Run runs blocking loop getting events from all providers and updating all mappers on each event

func (*Service) Servers

func (s *Service) Servers() (servers []string)

Servers return list of all servers, skips "*" (catch-all/default)

type URLMapper

type URLMapper struct {
	Server     string
	SrcMatch   regexp.Regexp
	Dst        string
	ProviderID ProviderID
	PingURL    string
	MatchType  MatchType

	AssetsLocation string
	AssetsWebRoot  string
}

URLMapper contains all info about source and destination routes

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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