diff --git a/actions/reconfigure.go b/actions/reconfigure.go index e1876c8f..4d6ea07c 100644 --- a/actions/reconfigure.go +++ b/actions/reconfigure.go @@ -174,7 +174,13 @@ func (m *Reconfigure) parseFrontTemplate(src string, sr *proxy.Service) string { func (m *Reconfigure) parseBackTemplate(src, usersList string, sr *proxy.Service) string { tmplUsersList, _ := template.New("template").Parse(usersList) - tmpl, _ := template.New("").Parse(src) + funcMap := template.FuncMap{ + "Split": func(s string, d string) []string { + arr := strings.Split(s, d) + return arr + }, + } + tmpl, _ := template.New("").Funcs(funcMap).Parse(src) var bufUsersList bytes.Buffer var buf bytes.Buffer tmplUsersList.Execute(&bufUsersList, sr) diff --git a/actions/reconfigure_test.go b/actions/reconfigure_test.go index 995fb6c5..061e4d6a 100644 --- a/actions/reconfigure_test.go +++ b/actions/reconfigure_test.go @@ -533,8 +533,8 @@ backend myService-be5555_2 func (s ReconfigureTestSuite) Test_GetTemplates_AddsHttpRequestSetPath_WhenReqPathSearchReplaceFormattedIsPresent() { s.reconfigure.ServiceDest = []proxy.ServiceDest{{ - Port: "1234", - Index: 0, + Port: "1234", + Index: 0, ReqPathSearchReplaceFormatted: []string{"this,that", "foo,bar"}, HttpsPort: 1234, }} @@ -558,16 +558,17 @@ backend https-myService-be1234_0 } func (s ReconfigureTestSuite) Test_GetTemplates_AddsBackendExtra() { - s.reconfigure.BackendExtra = "Additional backend" + s.reconfigure.BackendExtra = "Additional backend line 1||Additional backend line 2" s.reconfigure.ServiceDest = []proxy.ServiceDest{{Port: "1234", Index: 0}} expected := fmt.Sprintf(` backend myService-be1234_0 mode http http-request add-header X-Forwarded-Proto https if { ssl_fc } server myService myService:1234 - %s`, - s.reconfigure.BackendExtra, - ) + + Additional backend line 1 + Additional backend line 2 +`) _, backend, _ := s.reconfigure.GetTemplates() diff --git a/go.mod b/go.mod index a85b5ca4..b3ec3ace 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/jessevdk/go-flags v1.4.0 github.com/kelseyhightower/envconfig v1.3.0 github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect - github.com/mitchellh/mapstructure v1.0.0 + github.com/mitchellh/mapstructure v1.1.2 github.com/prometheus/client_golang v0.8.0 github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 // indirect github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e diff --git a/go.sum b/go.sum index bebabbb2..ba15cfd9 100644 --- a/go.sum +++ b/go.sum @@ -21,6 +21,8 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0j github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/mitchellh/mapstructure v1.0.0 h1:vVpGvMXJPqSDh2VYHF7gsfQj8Ncx+Xw5Y1KHeTRY+7I= github.com/mitchellh/mapstructure v1.0.0/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v0.8.0 h1:1921Yw9Gc3iSc4VQh3PIoOqgPCZS7G/4xQNVUp8Mda8= diff --git a/proxy/template.go b/proxy/template.go index 04939bee..0cd40526 100644 --- a/proxy/template.go +++ b/proxy/template.go @@ -314,7 +314,9 @@ backend {{$.AclName}}-be{{$sd.Port}}_{{.Index}} {{- end}} {{- end}} {{- if ne $.BackendExtra ""}} - {{ $.BackendExtra }} +{{$arr := Split $.BackendExtra "||"}} +{{range $k, $v := $arr}} {{$v}} +{{end}} {{- end}} {{- end}} {{- end}} @@ -382,7 +384,9 @@ backend https-{{$.AclName}}-be{{.HttpsPort}}_{{.Index}} {{- end}} {{- end}} {{- if ne $.BackendExtra ""}} - {{ $.BackendExtra }} + {{$arr := Split $.BackendExtra "||"}} + {{range $k, $v := $arr}} {{$v}} + {{end}} {{- end}} {{- end}} {{- end}}`