From 7e8dca4ccc75340a8b15fa4d0da9eced138632c2 Mon Sep 17 00:00:00 2001 From: Umputun Date: Thu, 20 May 2021 13:14:37 -0500 Subject: [PATCH] allow skipping ping param in static provider --- app/discovery/provider/static.go | 10 ++++++++-- app/discovery/provider/static_test.go | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/discovery/provider/static.go b/app/discovery/provider/static.go index 12968f5..9adc11d 100644 --- a/app/discovery/provider/static.go +++ b/app/discovery/provider/static.go @@ -24,11 +24,17 @@ func (s *Static) Events(_ context.Context) <-chan discovery.ProviderID { // List all src dst pairs func (s *Static) List() (res []discovery.URLMapper, err error) { + // inp is 4 elements string server,source_url,destination,ping + // the last one can be omitted if no ping required parse := func(inp string) (discovery.URLMapper, error) { elems := strings.Split(inp, ",") - if len(elems) != 4 { + if len(elems) < 3 { return discovery.URLMapper{}, fmt.Errorf("invalid rule %q", inp) } + pingURL := "" + if len(elems) == 4 { + pingURL = strings.TrimSpace(elems[3]) + } rx, err := regexp.Compile(strings.TrimSpace(elems[1])) if err != nil { return discovery.URLMapper{}, fmt.Errorf("can't parse regex %s: %w", elems[1], err) @@ -45,7 +51,7 @@ func (s *Static) List() (res []discovery.URLMapper, err error) { Server: strings.TrimSpace(elems[0]), SrcMatch: *rx, Dst: dst, - PingURL: strings.TrimSpace(elems[3]), + PingURL: pingURL, ProviderID: discovery.PIStatic, MatchType: discovery.MTProxy, } diff --git a/app/discovery/provider/static_test.go b/app/discovery/provider/static_test.go index 2638a20..d61240e 100644 --- a/app/discovery/provider/static_test.go +++ b/app/discovery/provider/static_test.go @@ -24,6 +24,7 @@ func TestStatic_List(t *testing.T) { {"123", "", "", "", "", false, true}, {"example.com , 123, 456 ,ping", "example.com", "123", "456", "ping", false, false}, {"example.com,123, assets:456, ping ", "example.com", "123", "456", "ping", true, false}, + {"example.com,123, assets:456 ", "example.com", "123", "456", "", true, false}, } for i, tt := range tbl {