mirror of
https://github.com/umputun/reproxy.git
synced 2024-09-11 08:55:25 +03:00
allow skipping ping param in static provider
This commit is contained in:
parent
0c1218b3eb
commit
7e8dca4ccc
@ -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,
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user