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 ¶
- func Contains(e string, s []string) bool
- func ParseOnlyFrom(s string) (res []string)
- type MatchType
- type MatchedRoute
- type Matches
- type Provider
- type ProviderID
- type ProviderMock
- type RedirectType
- type Service
- func (s *Service) CheckHealth() (pingResult map[string]error)
- func (s *Service) Mappers() (mappers []URLMapper)
- func (s *Service) Match(srv, src string) (res Matches)
- func (s *Service) Run(ctx context.Context) error
- func (s *Service) ScheduleHealthCheck(ctx context.Context, interval time.Duration)
- func (s *Service) Servers() (servers []string)
- type URLMapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseOnlyFrom ¶ added in v1.1.0
ParseOnlyFrom parses comma separated list of IPs
Types ¶
type MatchedRoute ¶ added in v0.6.0
MatchedRoute contains a single match used to produce multi-matched Matches
type Matches ¶ added in v0.6.0
type Matches struct { MatchType MatchType Routes []MatchedRoute }
Matches returns result of url mapping. May have multiple routes. Lack of any routes means no match was wound
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" PIConsulCatalog ProviderID = "consul-catalog" )
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 RedirectType ¶ added in v0.8.0
type RedirectType int
RedirectType defines types of redirects
const ( RTNone RedirectType = 0 RTPerm RedirectType = 301 RTTemp RedirectType = 302 )
enum of all redirect types
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service implements discovery with multiple providers and url matcher
func NewService ¶
NewService makes service with given providers
func (*Service) CheckHealth ¶ added in v0.6.0
CheckHealth starts health-check for service's mappers
func (*Service) Match ¶
Match url to all mappers. Returns Matches with potentially multiple destinations for MTProxy. For MTStatic always a single match because fail-over doesn't supported for assets
func (*Service) Run ¶
Run runs blocking loop getting events from all providers and updating all mappers on each event
func (*Service) ScheduleHealthCheck ¶ added in v0.6.0
ScheduleHealthCheck starts background loop with health-check
type URLMapper ¶
type URLMapper struct { Server string SrcMatch regexp.Regexp Dst string ProviderID ProviderID PingURL string MatchType MatchType RedirectType RedirectType KeepHost *bool OnlyFromIPs []string AssetsLocation string // local FS root location AssetsWebRoot string // web root location AssetsSPA bool // spa mode, redirect to webroot/index.html on not found // contains filtered or unexported fields }
URLMapper contains all info about source and destination routes